我不明白为什么我得到这个错误:AttributeError的:“结果集”对象有没有属性“find_all” Beautifulsoup
我有一个非常简单的功能:
def scrape_a(url):
r = requests.get(url)
soup = BeautifulSoup(r.content)
news = soup.find_all("div", attrs={"class": "news"})
for links in news:
link = news.find_all("href")
return link
这里是网页的日estructure我试图刮:
<div class="news">
<a href="www.link.com">
<h2 class="heading">
heading
</h2>
<div class="teaserImg">
<img alt="" border="0" height="124" src="/image">
</div>
<p> text </p>
</a>
</div>
为什么要循环播放'news',然后调用'news.find_all()'?大概你打算使用'links.find_all'来代替? –
此外,'href'是标签的*属性*,而不是标签名。 –
另外,你的意思是只返回*第一个*结果? –