我想使用BeautifulSoup从谷歌专利搜索中抓取专利链接,但我不确定谷歌是否将其html转换为无法通过BeautifulSoup解析的javascript,也不确定问题出在哪里。
下面是一些简单的代码:
url = 'https://patents.google.com/?assignee=Roche&after=priority:20110602&type=PATENT&num=100'
soup = BeautifulSoup(requests.get(url).content, 'html.parser')
links = []
for link in soup.find_all('a', href=True):
print(link['href'])我还想将链接附加到列表中,但没有打印任何内容,因为没有来自soup的'a‘标记。有没有办法获取所有专利的链接?
发布于 2021-06-03 17:19:22
数据是动态呈现的,所以很难从bs4获取,所以你可以尝试进入chrome开发者模式。
然后转到网络选项卡,您现在可以找到xhr选项卡重新加载您的网页,因此在名称选项卡下会有链接,其中一个链接包含json格式的所有数据
因此您可以复制链接地址,并使用requests模块进行调用,现在您可以提取所需的任何数据
此外,如果你想要单独的链接,所以它是由publication_number制成的,你可以将它与旧链接连接起来,以获得出版物的链接。
import requests
main_url="https://patents.google.com/"
params="?assignee=Roche&after=priority:20110602&type=PATENT&num=100"
res=requests.get("https://patents.google.com/xhr/query?url=assignee%3DRoche%26after%3Dpriority%3A20110602%26type%3DPATENT%26num%3D100&exp=")
main_data=res.json()
data=main_data['results']['cluster']
for i in range(len(data[0]['result'])):
num=data[0]['result'][i]['patent']['publication_number']
print(num)
print(main_url+"patent/"+num+"/en"+params)输出:
US10287352B2
https://patents.google.com/patent/US10287352B2/en?assignee=Roche&after=priority:20110602&type=PATENT&num=100
US10364292B2
https://patents.google.com/patent/US10364292B2/en?assignee=Roche&after=priority:20110602&type=PATENT&num=100
US10494633B2
.....图片:

https://stackoverflow.com/questions/67809327
复制相似问题