使用python+谷歌自定义搜索API搜索专利

2024-04-19 22:03:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用google自定义搜索API以编程方式探索uspto。作为第一步和理智,我试着运行一个现有的脚本, Posted here at Stack Overflow零钱(urllib.quote成为urllib.parse.quote). 代码如下:

import requests
import urllib
import time
import json

access_token = <get yours by signing up for google custom search engine api>
cse_id = <get yours by signing up for google custom search engine api>

# Build url
start=1
search_text = "+(inassignee:\"Altera\" | \"Owner name: Altera\") site:www.google.com/patents/"
# &tbm=pts sets you on the patent search
url = 'https://www.googleapis.com/customsearch/v1?key='+access_token+'&cx='+cse_id+'&start='+str(start)+'&num=10&tbm=pts&q='+ urllib.parse.quote(search_text)

response = requests.get(url)

response.json()
f = open('Sample_patent_data'+str(int(time.time()))+'.txt', 'w')
f.write(json.dumps(response.json(), indent=4))
f.close()

以下是我在响应文件中得到的信息:

^{pr2}$

搜索出了什么问题? 这不是身份验证错误,怎么了? 谢谢大家,祝你有个愉快的一天!在


Tags: importtokenjsonurlsearchgetaccesstime
2条回答

我想你的API密钥有问题。 你可以在Google Custom Search Api keeps giving me "usageLimits" error找到一个类似的问题。 你可以试着申请一个新的钥匙。在

在那之后,你一定要使用google自定义搜索API吗?如果您计划发出少量请求,请考虑使用https://pypi.org/project/google-search/。在

希望有帮助。在

如果你只想使用谷歌专利为你的搜索,你可以配置它从自定义搜索设置和添加它作为网站到搜索选项。删除网址:www.google.com/patents/从搜索_文本和它应该工作。在

相关问题 更多 >