Last active
November 12, 2022 14:08
-
-
Save pixyfox/66a26833da0fbad1fb073ab4400cdb4d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Perform searches | |
wait = 6 # in seconds | |
print('Number of queries to do: ', len(keywords) * len(geo)) | |
# Prepare containers | |
trends = dict.fromkeys(geo) | |
errors_list = [] | |
cnt = 1 | |
# Start loops | |
for g in geo: | |
trends[g] = {} | |
for k in keywords: | |
try: | |
time.sleep(wait) | |
pytrends.build_payload([k], timeframe='all', geo=g, gprop='') | |
trends[g][k] = pytrends.interest_over_time()[k] | |
#print(cnt, 'Success: ', g, k) | |
except: | |
print(cnt, ') Error: ', g, ' & ', k) | |
errors_list.append([g,k]) | |
cnt+=1 | |
print('\nDone -', len(errors_list), 'errors left') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment