Searching for patents with python+google custom search API

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Searching for patents with python+google custom search API



I'm trying to explore the uspto programmatically using the google custom search API. As a first step and sanity, I tried to run an existing script,
Posted here at Stack Overflow with a small change (urllib.quote became urllib.parse.quote).
Here's the code:


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()



Here's what I got in the response file:



"error":
"errors": [

"domain": "usageLimits",
"reason": "keyInvalid",
"message": "Bad Request"

],
"code": 400,
"message": "Bad Request"




What's wrong with the search?
It's not an authentication error, so what's wrong?
Thanks everyone and have a nice day (-:!




2 Answers
2



I think there is something wrong with your API key.
You can find a similar question at Google Custom Search Api keeps giving me "usageLimits" error.
You could try requesting a new key.



After that, do you definitely have to use google custom search API? If you plan to make a small number of requests, consider using https://pypi.org/project/google-search/.



Hope it helps.



If you want use just google patent for your search you can configure it from custom search set up and add it as Sites to search option. Remove site:www.google.com/patents/ from search_text and it should work.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard