-
Notifications
You must be signed in to change notification settings - Fork 1
/
ggtrend_test.py
41 lines (30 loc) · 1.07 KB
/
ggtrend_test.py
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
import pandas as pd
from pytrends.request import TrendReq
import json
pytrend = TrendReq()
rising_df_all = pd.DataFrame()
kw_list=[""]
pytrend.build_payload(kw_list,cat=3, timeframe='today 1-m',geo="TH")
# Form Request
related_payload = dict()
request_json = pytrend.related_queries_widget_list[0]
# print(request_json)
related_payload["req"] = json.dumps(request_json["request"])
related_payload["token"] = request_json["token"]
related_payload["tz"] = pytrend.tz
# print(related_payload)
# Send Request
req_json = pytrend._get_data(
url=TrendReq.RELATED_QUERIES_URL,
method=TrendReq.GET_METHOD,
trim_chars=5,
params=related_payload,
)
result_json = pd.DataFrame(req_json)
result_json.to_json('result.json', force_ascii = False)
rising_df = pd.DataFrame(req_json['default']['rankedList'][1]["rankedKeyword"])
# print(req_json['default']['rankedList'][1]["rankedKeyword"])
# rising_df.to_json('result.json')
rising_df = rising_df[['query', 'value']]
rising_df_all = rising_df_all.append(rising_df, ignore_index=True)
# print(rising_df_all)