如何获取位于<;的data href属性中的url;a>;在python中使用BeautifulSoup?

如何获取位于<;的data href属性中的url;a>;在python中使用BeautifulSoup?,python,beautifulsoup,Python,Beautifulsoup,我不知道为什么它无法访问锚定标签的data href属性。您的链接可能已失效;我收到一个404错误。您需要为汤中的标记使用。查找所有('a'):打印(标记['data-href'])…并将?参数插入url:https://www.google.co.in/search?q=...。。。 import requests from bs4 import BeautifulSoup as soup result = requests.get("https://www.google.co.in/se

我不知道为什么它无法访问锚定标签的data href属性。

您的链接可能已失效;我收到一个404错误。您需要为汤中的标记使用
。查找所有('a'):打印(标记['data-href'])
…并将
参数插入
url
https://www.google.co.in/search?q=...
。。。
import requests
from bs4 import BeautifulSoup as soup


result = requests.get("https://www.google.co.in/searchq=ntest&oq=ntest&aqs=chrome..69i57j69i61j35i39l2j0l2.4898j0j7&sourceid=chrome&ie=UTF-8")
page = result.text
doc = soup(page,"html5lib")

a = doc.find_all('h3',{'class':'r'})

for i in a:
    b = i.a
    print(b.get('data-href'))