【问题标题】:Searching for patents with python+google custom search API使用 python+google 自定义搜索 API 搜索专利
【发布时间】: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"
    }
}

搜索出了什么问题? 这不是身份验证错误,所以出了什么问题? 谢谢大家,祝你有美好的一天(-:!

【问题讨论】:

    标签: python json api search


    【解决方案1】:

    我认为您的 API 密钥有问题。 您可以在Google Custom Search Api keeps giving me "usageLimits" error 找到类似的问题。 您可以尝试申请新密钥。

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

    希望对你有帮助。

    【讨论】:

      【解决方案2】:

      如果您只想使用谷歌专利进行搜索,您可以从自定义搜索设置中对其进行配置,并将其作为站点添加到搜索选项。从 search_text 中删除 site:www.google.com/patents/ 它应该可以工作。

      【讨论】:

        猜你喜欢
        • 2016-04-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-07-17
        • 2012-06-18
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多