小编Koo*_*len的帖子

用美丽的汤提取href

我使用此代码来访问我的链接:

links = soup.find("span", { "class" : "hsmall" })
links.findNextSiblings('a')
for link in links:
  print link['href']
  print link.string
Run Code Online (Sandbox Code Playgroud)

链接没有ID或类或其他什么,它只是一个带有href属性的经典链接.

我的脚本的响应是:

print link['href']
TypeError: string indices must be integers
Run Code Online (Sandbox Code Playgroud)

你能帮助我获得href价值吗?谢谢 !

python beautifulsoup href

6
推荐指数
2
解决办法
9963
查看次数

标签 统计

beautifulsoup ×1

href ×1

python ×1