【发布时间】:2015-03-22 00:08:04
【问题描述】:
我正在尝试使用 urllib2 读取页面,以便从页面中提取数据。部分页面是每次加载时生成的,当我使用 urllib2 读取 url 时,这部分不在我得到的 html 中。
网址是 http://nametrends.net/name.php?name=Ruby ,我正在尝试获取为图表生成的表格。 例如:
<div aria-label="A tabular representation of the data in the chart." style="position: absolute; left: -10000px; top: auto; width: 1px; height: 1px; overflow: hidden;">
<table>
<tbody>
<tr><td>Sat Feb 01 1947 00:00:00 GMT-0500 (EST)</td><td>0.048</td><td>0</td></tr>
</tbody>
</table>
</div>
我当前的代码是:
import urllib2
from bs4 import BeautifulSoup
req = urllib2.Request('http://nametrends.net/name.php?name=Ruby')
response = urllib2.urlopen(req)
the_page = response.read()
html = BeautifulSoup(the_page)
print "tabular" in html
for table in html.find_all('table'):
print 1
它没有找到那个表格,并且html中没有带有文本表格的div(这是包含表格的div的标签)
【问题讨论】: