可以使用css选择器来定位具有特定href值的'a'标签。例如,要找到href值为'http://example.com/'的'a'标签,可以使用以下代码:
from bs4 import BeautifulSoup
html = '''
Google
Example
Bing
Another Example
'''
soup = BeautifulSoup(html, 'html.parser')
a_tags = soup.select('a[href="http://example.com"]')
for a in a_tags:
print(a.text)
输出结果:
Example
Another Example