Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions serpapi/google_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@ class GoogleSearch(SerpApiClient):
"""GoogleSearch enables to search google and parse the result.
```python
from serpapi import GoogleSearch
query = GoogleSearch({"q": "coffee", "location": "Austin,Texas"})
query = GoogleSearch(
{
"q": "coffee",
"location": "Austin,Texas",
},
timeout = 60,
ssl_verify = True,
)
data = query.get_json()
```

https://github.com/serpapi/google-search-results-python
"""

def __init__(self, params_dict):
super(GoogleSearch, self).__init__(params_dict, GOOGLE_ENGINE)
def __init__(self, params_dict, timeout = 60, ssl_verify = True):
super(GoogleSearch, self).__init__(params_dict, GOOGLE_ENGINE, timeout, ssl_verify)
22 changes: 13 additions & 9 deletions serpapi/serp_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ class SerpApiClient(object):
"""SerpApiClient enables to query any search engines supported by SerpApi and parse the results.
```python
from serpapi import GoogleSearch
search = SerpApiClient({
"q": "Coffee",
"location": "Austin,Texas",
"engine": "google",
"api_key": "<your private key>"
})
search = SerpApiClient(
{
"q": "Coffee",
"location": "Austin,Texas",
"engine": "google",
"api_key": "<your private key>",
},
timeout = 60,
ssl_verify = True,
)
data = search.get_json()
```

Expand All @@ -24,10 +28,11 @@ class SerpApiClient(object):
BACKEND = "https://serpapi.com"
SERP_API_KEY = None

def __init__(self, params_dict, engine = None, timeout = 60000):
def __init__(self, params_dict, engine = None, timeout = 60, ssl_verify = True):
self.params_dict = params_dict
self.engine = engine
self.timeout = timeout
self.ssl_verify = ssl_verify

def construct_url(self, path = "/search"):
self.params_dict['source'] = 'python'
Expand All @@ -47,8 +52,7 @@ def get_response(self, path = '/search'):
url = None
try:
url, parameter = self.construct_url(path)
# print(url)
response = requests.get(url, parameter, timeout=self.timeout)
response = requests.get(url, parameter, timeout=self.timeout, verify=self.ssl_verify)
return response
except requests.HTTPError as e:
print("fail: " + url)
Expand Down