pytrends icon indicating copy to clipboard operation
pytrends copied to clipboard

Fix keyword name issue

Open alicanyuksel opened this issue 2 years ago • 0 comments

Hello,

It is possible to observe compound keywords in the same keyword on Google Trends like 'blockchain + bitcoin'. Your try except block only takes the first element of the list. That's why, in the dictionary that the function returns, we only find "blockchain" as a key but not the real keyword which is "blockchain + bitcoin".

API response example for a given multi keyword: [{'type': 'BROAD', 'value': 'blockchain'}, {'type': 'BROAD', 'value': 'bitcoin'}]

If you don't want to use keywordName attribute in PR, here is my second suggestion:

try:
    kw = " + ".join(
        each_kw_dict["value"]
        for each_kw_dict in request_json["request"]["restriction"]["complexKeywordsRestriction"][
            "keyword"
        ]
    )
except KeyError:
    kw = ""

I work a lot on this kind of keywords, hoping that it will be merged. Thanks

alicanyuksel avatar Sep 17 '22 22:09 alicanyuksel