如何获取该粗体元素的文本? 预先感谢
<tr>
<td>
<div class="graph-legend-color"
style="width:12px;height:11px;background-
color:#3366CC">
</div>
</td>
<td class="percent">48,9 %</td>
<td class="number">92.234</td>
**<td>Proxy-Block Types From Download Media Type Blocklist</td>**
</tr>
答案 0 :(得分:1)
如您所见,粗体元素(<td>
是<td>
标签内的最后<tr>
元素。因此,您选择了<td>
标记内的所有<tr>
标记,并获得了索引为-1
的元素(在Python中表示最后一个索引):
data = """
<tr>
<td>
<div class="graph-legend-color"
style="width:12px;height:11px;background-
color:#3366CC">
</div>
</td>
<td class="percent">48,9 %</td>
<td class="number">92.234</td>
<td>Proxy-Block Types From Download Media Type Blocklist</td>
</tr>"""
from bs4 import BeautifulSoup
soup = BeautifulSoup(data, 'lxml')
print(soup.select('tr > td')[-1].text)
打印:
Proxy-Block Types From Download Media Type Blocklist