GeneralMills / pytrends

Pseudo API for Google Trends
Other
3.21k stars 813 forks source link

I discoverd an bug inthe library in _get_data method #536

Open ahmed-ellaban opened 1 year ago

ahmed-ellaban commented 1 year ago

when you sent more than a keyword to build_payload the related_topics won't return the data the reason for this is when you the library use the _get_data method and it sends a request to https://trends.google.com/trends/api/explore it doesn't return any widget for RELATED_TOPICS so _tokens return the related_topics_widget_list as an empty list but when you just send a keyword to build_payload _get_data returns an result this an example of a result returned with a keyword https://trends.google.com/trends/api/explore?hl=ar&tz=-120&req=%7B%22comparisonItem%22%3A%20%5B%7B%22keyword%22%3A%20%22Apple%22%2C%20%22time%22%3A%20%222022-10-05%202022-10-07%22%2C%20%22geo%22%3A%20%22%22%7D%5D%2C%20%22category%22%3A%200%2C%20%22property%22%3A%20%22%22%7D&tz=-120 and this is for many keywords

Keywords=['Tesla', 'Apple', 'Facebook']
pytrends.build_payload(Keywords, timeframe='2022-10-05 2022-10-07', geo='US')

data=pytrends._get_data(
            url=TrendReq.GENERAL_URL,
            method=TrendReq.GET_METHOD,
            params=pytrends.token_payload,
            trim_chars=4,
        ) # check me
ahmed-ellaban commented 1 year ago

you can also check by trying one keyword and you will see it return the correct result

Keywords=['Tesla', 'Apple', 'Facebook']
pytrends.build_payload([Keywords[0]], timeframe='2022-10-05 2022-10-07', geo='US') 
# you should pass a list I tried it if you passed a string it deals with a list of characters

data=pytrends._get_data(
            url=TrendReq.GENERAL_URL,
            method=TrendReq.GET_METHOD,
            params=pytrends.token_payload,
            trim_chars=4,
        ) # check me
emlazzarin commented 1 year ago

Thanks for filing this @ahmedallban. I'm not totally sure I follow. What is the result you expect versus the result you're seeing? And is there any chance you could submit a fix?

ahmed-ellaban commented 1 year ago

the result I should get isn't empty result but I get an empty result if I searched more than a keyword

jackstruck commented 1 year ago

Unsure if related https://github.com/GeneralMills/pytrends/issues/176, but seems to be the same issue. Confirmed in version 4.8.0