我有一个包含4到5个不同表的html文档。我想要的是一个class=“data”属性。我不知道怎么让BeautifulSoup只返回那张表。在
soup = BeautifulSoup(myhtml)
t = soup.findAll('table', 'class="data"')
for table in t:
rows = table.findAll('tr')
for tr in rows:
cols = tr.findAll('td')
for td in cols:
print td
如果我删除上面的“class=”data“',我会从每个表中得到结果。是否可以只选择class=“data”的一个。或者,有没有其他方法可以迭代这些表?在
将
class
属性指定为字典,如下所示:如果使用bs4,则可以使用
^{pr2}$select
方法使用CSS选择器:查看以下代码:
属性类需要under引用
相关问题 更多 >
编程相关推荐