我正在使用 Beautiful Soup 4 来抓取页面。有一段我不想要的文本:
<p class="MsoNormal" style="text-align: center"><b>
<span lang="EN-US" style="font-family: Arial; color: blue">
<font size="4">1 </font></span>
<span lang="AR-SA" dir="RTL" style="font-family: Arial; color: blue">
<font size="4">ـ</font></span><span lang="EN-US" style="font-family: Arial; color: blue"><font size="4">
сүрә фатиһә</font></span></b></p>
它的独特之处在于它有一个标签。我已经使用 findall() 来获取所有
标签。所以现在我有一个 for 循环,例如:
for el in doc.findall('p'):
if el.hasChildTag('b'):
break;
不幸的是bs4没有“hasChildTag”功能
最佳答案
也应该可以使用 css 选择器。
http://www.crummy.com/software/BeautifulSoup/bs4/doc/#css-selectors
soup.select("p b")
关于python - 漂亮的汤检查标签中的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14307042/