【问题标题】:Django get data from html table for databaseDjango 从 html 表中获取数据库的数据
【发布时间】:2015-12-13 20:09:43
【问题描述】:

我需要使用 django 框架获取数据,然后写入数据库。使用 javascript 将行添加到表中。例如:

<table id="tbl" >
<thead >
    <tr>
        <th>Name</th>        
        <th>Phone</th>
        <th>Sarlay</th>
        <th>P1</th>
        <th>P2</th>
    </tr>
</thead>
<tbody class="scrollContent">
</tbody>
</table>
<button type="button" onclick="Add_Row()" class="btn btn-primary">Add</button> 
<script >
function Add_Row()
{
document.getElementById("scrolltable").insertRow(-1).innerHTML = '    <tr><td><input class="form-control" name="inp" type="text" value=""/></td><td><input class="form-control" name="inp" type="text" value=""/></td><td><input class="form-control" name="inp" type="text" value=""/></td><td><input class="form-control" name="inp" type="text" value=""/></td><td><input class="form-control" name="inp" type="text" value=""/></td></tr>';
}
</script>

谁知道如何从这个表中获取数据?

附:我尝试使用 BeautifulSoup 来解决这个问题,但它没有帮助我。

【问题讨论】:

  • 在目前的形式中,这是一个接近投票的避雷针。更新问题以显示您尝试过的内容。 BeautifulSoup 不起作用,因为您似乎正在使用 javascripts 生成页面。
  • 这与 Django 和 BeautifulSoup 无关

标签: mysql django


【解决方案1】:

您不应在没有所有者权限的情况下解析来自网站的数据。

一种方法是使用浏览器的“开发人员工具”或检查该页面的源代码并找出 js 从何处填充这些表。如果幸运的话,您可能会找到某种合理格式(json 或 xml)的源代码。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-31
    相关资源
    最近更新 更多