-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.py
More file actions
50 lines (40 loc) · 1.19 KB
/
client.py
File metadata and controls
50 lines (40 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from requests import request, Response
from typing import TypedDict, Optional
import urllib.parse
from .default_headers import default_headers
class GetSearchResultsParams(TypedDict, total=False):
q: str
location: Optional[str]
uule: Optional[str]
domain: Optional[str]
gl: Optional[str]
hl: Optional[str]
lr: Optional[list]
ludocid: Optional[str]
lsig: Optional[str]
kgmid: Optional[str]
si: Optional[str]
tbs: Optional[str]
safe: Optional[str]
filter: Optional[int]
tbm: Optional[str]
deviceType: Optional[str]
start: Optional[int]
num: Optional[int]
class GoogleSerpApi:
api_url = "https://api.hasdata.com/scrape/google/serp"
def __init__(self, api_key: str):
self.api_key = api_key
def getSearchResults(
self,
params: GetSearchResultsParams,
**kwargs
) -> Response:
headers = {
"x-api-key": self.api_key
}
headers.update(default_headers)
params["source"] = "python_sdk"
url_params = urllib.parse.urlencode(params)
url = self.api_url + "/" + "?" + url_params
return request("GET", url, headers=headers, **kwargs)