使用python搜索专利+;谷歌自定义搜索API
我正在尝试使用google自定义搜索API以编程方式探索uspto。作为第一步,我试着运行一个现有的脚本, 只做了一个小改动(urllib.quote变成了urllib.parse.quote)。 代码如下:使用python搜索专利+;谷歌自定义搜索API,python,json,api,search,Python,Json,Api,Search,我正在尝试使用google自定义搜索API以编程方式探索uspto。作为第一步,我试着运行一个现有的脚本, 只做了一个小改动(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
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()
搜索有什么问题吗?
这不是身份验证错误,那么怎么了?
谢谢大家,祝大家度过愉快的一天(-:!我认为您的API密钥有问题。 你可以在网站上找到一个类似的问题。 你可以试着申请一把新钥匙
之后,你一定要使用谷歌定制搜索API吗?如果你打算做少量请求,考虑使用./P>
希望有帮助。如果您想在搜索中仅使用谷歌专利,您可以从“自定义搜索设置”中配置它,并将其添加为“站点到搜索”选项。从搜索文本中删除站点:www.google.com/patents/,它应该可以工作
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "keyInvalid",
"message": "Bad Request"
}
],
"code": 400,
"message": "Bad Request"
}
}