@@ -44,8 +44,9 @@ def __init__(self, hl='en-US', tz=360, geo='', proxies=''):
4444 self .hl = hl
4545 self .geo = geo
4646 self .kw_list = list ()
47- self .proxies = proxies #add a proxy option
47+ self .proxies = proxies #add a proxy option
4848 #proxies format: {"http": "http://192.168.0.1:8888" , "https": "https://192.168.0.1:8888"}
49+ self .cookies = requests .get ('https://trends.google.com' ).cookies
4950
5051 # intialize widget payloads
5152 self .token_payload = dict ()
@@ -64,16 +65,13 @@ def _get_data(self, url, method=GET_METHOD, trim_chars=0, **kwargs):
6465 :param kwargs: any extra key arguments passed to the request builder (usually query parameters or data)
6566 :return:
6667 """
68+ s = requests .session ()
69+ if self .proxies != '' :
70+ s .proxies .update (self .proxies )
6771 if method == TrendReq .POST_METHOD :
68- s = requests .session ()
69- if self .proxies != '' :
70- s .proxies .update (self .proxies )
71- response = s .post (url , ** kwargs )
72+ response = s .post (url , cookies = self .cookies , ** kwargs )
7273 else :
73- s = requests .session ()
74- if self .proxies != '' :
75- s .proxies .update (self .proxies )
76- response = s .get (url ,** kwargs )
74+ response = s .get (url , cookies = self .cookies , ** kwargs )
7775
7876 # check if the response contains json and throw an exception otherwise
7977 # Google mostly sends 'application/json' in the Content-Type header,
0 commit comments