我不明白爲什麼我得到這個錯誤: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'是標籤的*屬性*,而不是標籤名。 –
另外,你的意思是隻返回*第一個*結果? –