Python 如何从Beauty soup中的锚定标记中提取href链接

Python 如何从Beauty soup中的锚定标记中提取href链接,python,url,beautifulsoup,href,urllib2,Python,Url,Beautifulsoup,Href,Urllib2,可能重复: 我用的是漂亮的汤,下面是我的代码 import urllib2 data = urllib2.urlopen("some_url") html_data = data.read() soup = BeautifulSoup(html_data) href_tags = soup.findAll('a') 结果: href_tags = [<a href="http://www.exampl.com/score_card" target="_blank" style="fo

可能重复:

我用的是漂亮的汤,下面是我的代码

import urllib2
data = urllib2.urlopen("some_url")
html_data = data.read()
soup = BeautifulSoup(html_data)
href_tags = soup.findAll('a')
结果:

href_tags = 
[<a href="http://www.exampl.com/score_card" target="_blank" style="font-family:arial;color:#192e94;">Click Here</a>, 
<a href="https://example.icims.com/jobs/search?pr=5">what is this</a>,
<a href="https://example.com/search?pr=6">Cool</a>,
<a href="https://example.com/help/host/search?pr=7">Hello</a>]
href\u标签=
[, 
,
,
]
但实际上我想从所有锚定标记中提取href,我如何才能提取href标记


提前感谢………

尝试在比赛中循环:

import urllib2
data = urllib2.urlopen("some_url")
html_data = data.read()
soup = BeautifulSoup(html_data)

for a in soup.findAll('a',href=True):
    print a['href']

从头到脚-
href\u tags=[tag['href']表示汤中的标签。findAll('a',{'href':True})]


{'href':True}
确保有一个href属性,以便
标记.attr['href']
不会失败。

这一项可能会对@novus42有所帮助:非常感谢,它提供了更多信息