因此,我尝试使用以下代码刮取表的内容:
url = 'https://www.eleconomista.es/indices-mundiales/'
r = requests.get(url)
data = r.text
soup = BeautifulSoup(data,"html5lib")
table=soup.find('table',{'class' : 'table tableFlex table-striped footable footable-1 breakpoint breakpoint-xs'})
print( table)
输出为
None
但我想打印“欧罗巴”表格
我想了解为什么我没有收到预期的输出,以及如何克服这个问题,为今后的案件
表有“table tableFlex table striped”类。所以下面的方法就行了
您看到的是
None
,因为页面使用了大量Javascript,并且动态地更改了标记的类—您在浏览器中看到的类与从requests
获得的类不同。因此,字符串'table tableFlex table-striped footable footable-1 breakpoint breakpoint-xs'
没有捕获任何内容。您可以尝试此脚本来捕获一些数据(数据表中只有<tr>
标记,因此只选择它们是可以的):印刷品:
相关问题 更多 >
编程相关推荐