python2使用beautifulsoup选择链接

时间:2018-01-14 10:29:13

标签: python html beautifulsoup

如何选择链接" https://www.jmir.org/2018/1/e1"在python中使用beautifulsoup?

<a ng-href="https://www.jmir.org/2018/1/e1" ng-bind-
html="toTrust(article._data.title)" class="ng-binding" 
href="https://www.jmir.org/2018/1/e1">A Perioperative eHealth Program to 
Enhance Postoperative Recovery After Abdominal Surgery: Process Evaluation of 
a Randomized Controlled Trial</a>

我已经尝试了以下代码,但它返回时没有我想要的上述链接。

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

1 个答案:

答案 0 :(得分:0)

您必须添加该类的名称:

soup.find('a',{'class':'ng-binding'})['href']