【发布时间】:2025-01-11 18:35:02
【问题描述】:
我有一个像下面这样的标签,我想用Beautiful Soup 选择它
<td align="right" class="simcal" valign="top"> Title:<br/></td>
当我尝试使用以下代码选择此标签时,一切正常。
# sample 1 :
my_tag = soup.find(
'td',
attrs={"align": "right", "class": "header2", "valign": 'top'},
)
# sample 2 :
my_tag = soup.find(
text=" Title:",
attrs={"align": "right", "class": "header2", "valign": 'top'},
)
但是当我尝试将这两者结合在一起时Beautiful Soup 找不到我想要的元素。
# This will fail
my_tag = soup.find(
'td',
text=" Title:",
attrs={"align": "right", "class": "header2", "valign": 'top'},
)
所以我的问题是有人可以向我解释这里发生了什么吗?
【问题讨论】:
标签: python-3.x web-scraping beautifulsoup web-crawler