【发布时间】:2019-07-02 18:48:03
【问题描述】:
我有一些具有以下结构的 HTML:
<div class="article">
<h1 class="header">Birth Date between 1919-01-01 and 2019-01-01, Oscar-Winning, Oscar-Nominated, Males (Sorted by Popularity Ascending) </h1>
<br class="clear"/>
<div class="desc">
<span>1-100 of 716 names.</span> // I WANT THIS ELEMENT
<span class="ghost">|</span> <a class="lister-page-next next-page" href="/search/name?birth_date=1919-01-01,2019-01-01&groups=oscar_winner,oscar_nominee&gender=male&count=100&start=101&ref_=rlm">Next »</a>
</div>
<br class="clear"/>
</div>
现在我正在尝试使用 bs4 从这个 html 中获取特定元素。我试着做:
webSoup = BeautifulSoup(html, 'html.parser')
nextUrl = webSoup.findChildren()[2][0]
但这给了我以下错误:
返回 self.attrs[key] 关键错误:0
所以,总结一下我的问题:
如何使用 bs4 从 html 文档中获取特定索引处的特定子项?
【问题讨论】:
标签: python html parsing web-scraping beautifulsoup