python beautifulsoup查找[具有特定锚文本的](file:C:UsersJiangDesktopspiderpagespythonpage_750_08.htm

python beautifulsoup查找[具有特定锚文本的](file:C:UsersJiangDesktopspiderpagespythonpage_750_08.htm,第1张

python /beautifulsoup查找[具有特定文本的](file:///C:/Users/Jiang/Desktop/spider/pages/python/page_750_08.htm

[

这样的事情行吗?

In [39]: from bs4 import BeautifulSoupIn [40]: s = """   ....: <a href="http://example.com">TEXT</a>   ....: <a href="http://example.com/link">TEXT</a>   ....: <a href="http://example.com/page">TEXT</a>   ....: <a href="http://dontmatchme.com/page">WRONGTEXT</a>"""In [41]: soup = BeautifulSoup(s)In [42]: for link in soup.findAll('a', href=True, text='TEXT'):   ....:     print link['href']   ....:   ....:http://example.comhttp://example.com/linkhttp://example.com/page

](file:///C:/Users/Jiang/Desktop/spider/pages/python/page_750_08.html)



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5617873.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存