簡體   English   中英

python2使用beautifulsoup選擇鏈接

[英]python2 select link using beautifulsoup

如何在python中使用beautifulsoup選擇鏈接“ https://www.jmir.org/2018/1/e1 ”?

<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"]

您必須添加類的名稱:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM