My question is in reference to Access Google Trends Data without a wrapper, or with the API: Python. I was able to follow along and get the google trends data from the graph on my own. However, manipulating the url to find a different search is my issue.
What iv'e done.
S1 Manually do google trends search for intended topic. S2 Manually extract 'api/widget' url and placed in code S3 Got graph information
When I attempt to take the 'AMC' from string and replace it with "GOOG". Thats when i get a "Expecting value: line 1 column 1 (char 0)".
'''
import requests
import json
url='https://trends.google.com/trends/api/widgetdata/multiline?hl=en-US&tz=300&req=%7B%22time%22:%222023-03-26T18%5C%5C:04%5C%5C:39+2023-03-27T18%5C%5C:04%5C%5C:39%22,%22resolution%22:%22EIGHT_MINUTE%22,%22locale%22:%22en-US%22,%22comparisonItem%22:%5B%7B%22geo%22:%7B%22country%22:%22US%22%7D,%22complexKeywordsRestriction%22:%7B%22keyword%22:%5B%7B%22type%22:%22BROAD%22,%22value%22:%22AMC+stock%22%7D%5D%7D%7D%5D,%22requestOptions%22:%7B%22property%22:%22%22,%22backend%22:%22CM%22,%22category%22:0%7D,%22userConfig%22:%7B%22userType%22:%22USER_TYPE_LEGIT_USER%22%7D%7D&token=APP6_UEAAAAAZCMsN6uqaWBPDC4ytcny8vODiNUMU7XQ&tz=300'
# change url from AMC to GOOG
url=url.replace("AMC","GOOG",1)
print(url)
url_2='https://trends.google.com/trends/api/widgetdata/multiline?hl=en-US&tz=300&req=%7B%22time%22:%222023-03-26T18%5C%5C:04%5C%5C:39+2023-03-27T18%5C%5C:04%5C%5C:39%22,%22resolution%22:%22EIGHT_MINUTE%22,%22locale%22:%22en-US%22,%22comparisonItem%22:%5B%7B%22geo%22:%7B%22country%22:%22US%22%7D,%22complexKeywordsRestriction%22:%7B%22keyword%22:%5B%7B%22type%22:%22BROAD%22,%22value%22:%22AMC+stock%22%7D%5D%7D%7D%5D,%22requestOptions%22:%7B%22property%22:%22%22,%22backend%22:%22CM%22,%22category%22:0%7D,%22userConfig%22:%7B%22userType%22:%22USER_TYPE_LEGIT_USER%22%7D%7D&token=APP6_UEAAAAAZCMsN6uqaWBPDC4ytcny8vODiNUMU7XQ&tz=300'
print(url_2)
response = requests.get(url
)
import json
data = json.loads(response.text.lstrip(")]}\',\n"))
for item in data['default']['timelineData']:
print(item['formattedAxisTime'], item['value'])
'''
I need to be able to change the URL to look up different stocks through the day. I tried using urlparse and urlsplit but may have not been using correctly.