【发布时间】:2015-06-04 06:57:09
【问题描述】:
这是我的 html 代码,现在我想使用美丽的汤从以下 html 代码中提取数据
<tr class="tr-option">
<td class="td-option"><a href="">A.</a></td>
<td class="td-option">120 m</td>
<td class="td-option"><a href="">B.</a></td>
<td class="td-option">240 m</td>
<td class="td-option"><a href="">C.</a></td>
<td class="td-option" >300 m</td>
<td class="td-option"><a href="">D.</a></td>
<td class="td-option" >None of these</td>
</tr>
这是我漂亮的汤代码
soup = BeautifulSoup(html_doc)
for option in soup.find_all('td', attrs={'class':"td-option"}):
print option.text
以上代码的输出:
A.
120 m
B.
240 m
C.
300 m
D.
None of these
但我想要以下输出
A.120 m
B.240 m
C.300 m
D.None of these
我该怎么办?
【问题讨论】:
标签: python html beautifulsoup