【发布时间】:2014-03-08 01:17:20
【问题描述】:
我尝试使用不同的代码片段来使用 bs 和 python 抓取表头的名称,每次我只得到一个空列表返回。这是我要提取的值:
<table class="table table-bordered table-striped table-hover data-grid ng-scope">
<thead>
<tr>
<th class="ng-isolate-scope sortable" data-colname="Advertiser" data-colsorter="sorter">
Advertiser
我想提取的信息是“data-colname”。这是我尝试过的:
for tx in soup.find_all('th'):
table_headers.append(tx.get('th.data-colname'))
#this returns an empty list, tried other combinations of this sort ... all returned an empty list
#Another attempt was:
spans = [x.text.strip() for x in soup.select('th.ng-isolate-scope data-colname')]
# returns errors
【问题讨论】:
-
你能告诉我
tx在这种情况下代表什么吗?谢谢
标签: python html web-scraping beautifulsoup