使用Beautiful Soup查找下一个出现的标签及其包含的文本

使用Beautiful Soup查找下一个出现的标签及其包含的文本,第1张

使用Beautiful Soup查找下一个出现的标签及其包含的文本

使用

find_next_sibling
(如果不是同级,请使用
find_next

>>> html = '''... <html>... <head>header... </head>... <blockquote>blah blah... </blockquote>... <p>eiaoiefj</p>... <blockquote>capture this next... </blockquote>... <p></p><strong>don'tcapturethis</strong>... <blockquote>... capture this too but separately after "capture this next"... </blockquote>... </html>... '''>>> from bs4 import BeautifulSoup>>> soup = BeautifulSoup(html)>>> quote1 = soup.blockquote>>> quote1.textu'blah blahn'>>> quote2 = quote1.find_next_siblings('blockquote')>>> quote2.textu'capture this nextn'


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

原文地址:https://54852.com/zaji/5650493.html

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

发表评论

登录后才能评论

评论列表(0条)

    保存