与美丽的汤提取HREF [英] Extracting href with Beautiful Soup
本文介绍了与美丽的汤提取HREF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用这个code获得存取权限到我的链接:
I use this code to get acces to my link :
links = soup.find("span", { "class" : "hsmall" })
links.findNextSiblings('a')
for link in links:
print link['href']
print link.string
链接没有ID或类或什么的,它只是一个href属性的经典环节。
Link have no ID or class or whatever, it's just a classic link with a href attribute.
我的剧本的反应是:
print link['href']
TypeError: string indices must be integers
你能帮助我获得href的值?
THX!
Can you help me to get href value ? Thx !
推荐答案
好了,现在可以与以下code:
Okay, it works now with following code :
linkSpan = soup.find("span", { "class" : "hsmall" })
link = [tag.attrMap['href'] for tag in linkSpan.findAll('a', {'href': True})]
for lien in link:
print "LINK = " + lien`
这篇关于与美丽的汤提取HREF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文