【发布时间】:2021-12-21 17:05:05
【问题描述】:
我正在使用 Python 中的 BeautifulSoup 进行“递归”项目。我已经阅读了官方文档和很多问题,但我仍然不明白。
from bs4 import BeautifulSoup
s = "<div>C<p><strong>A</strong>B</p></div>"
soup = BeautifulSoup(s, 'html.parser')
-
print(soup.find("p", recursive=False))给None
是不是因为我们在<div></div>之外找不到任何东西了?
-
print(soup.find("p").find(recursive=False))给<strong>A</strong>
如果我在第一个问题中的想法是正确的,
我猜这会给<p>B</p>,因为我们无法深入。但是为什么这要从<strong>开始呢?为什么不<p>?
另外,如何提取<p>B</p>?
【问题讨论】:
标签: python html beautifulsoup web-crawler