【发布时间】:2018-08-11 15:49:41
【问题描述】:
我正在尝试使用 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()
这是我在响应文件中得到的:
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "keyInvalid",
"message": "Bad Request"
}
],
"code": 400,
"message": "Bad Request"
}
}
搜索出了什么问题? 这不是身份验证错误,所以出了什么问题? 谢谢大家,祝你有美好的一天(-:!
【问题讨论】: