【发布时间】:2015-12-04 18:54:53
【问题描述】:
我正在使用beautifulsoup,有些我无法在a 标签中提取href,无论我做什么,它都会向我返回错误。这是我正在使用的功能
def scrape_a(url):
r = requests.get(url)
soup = BeautifulSoup(r.content)
news = soup.find_all("div", attrs={"class": "news"})
return news
html数据结构是
<div class="news">
<a href="www.link.com">
<h2 class="heading">
Kenyan police foil potential bomb attack in Nairobi mall
</h2>
<div class="teaserImg">
<img alt="" border="0" height="124" src="/image">
</div>
<p> text </p>
</a>
</div>
我想从中提取的是 href 和 h2 class='heading',每当我尝试获取这两者时,我都会得到一个错误,none type object has no attribute get item
【问题讨论】:
标签: python tags beautifulsoup