如何从BeautifulSoup.find()获取Beautiful Soup对象



这可能是一个新手问题,但我已经阅读了整个bs4文档,正在努力寻找问题的解决方案。

我基本上有一个BeautifulSoup对象,我从中调用.find((来定位某个div,然后我想在这个div上调用.find_all((。我尝试过这样的方法:

soup = bs4.BeautifulSoup(browser.page_source, "lxml")
competition = soup.find("div", class_="accordion-competition__content_main").contents
events = competition.find_all("div", class_="sport-event-card")
for event in competition:
print("EVENT: ", event)

没有用。

如何使用BS4过滤已过滤的部分?非常感谢您的帮助。我一直在这个问题上磕磕碰碰,还没有找到一个合适的解决方案来过滤一个部分。

soup = bs4.BeautifulSoup(browser.page_source, "lxml")
competition = soup.find("div", {"class": "accordion-competition__content_main"}) # get competition node
events = competition.find_all("div", {"class": "sport-event-card"}) # find inside competition node
for event in events:
print("EVENT: ", event)

最新更新