简体   繁体   中英

Get topic id from Google Trends for a topic name using Python

Using Python, I am attempting to scrape data from Google Trends for "topics" (as opposed to "search terms").

I am currently using the pytrends module, but it appears it's not (currently) possible to scrape topics rather than search terms, unless you know the topic_id .

Eg if you wanted to scrape the data for the topic_name "Holiday", you could search using the topic_id /m/03gkl , but only if you knew that that was the topic_id .

I have a list of topic names. I would like a corresponding list of topic ids. How can I achieve this?

It looks like I didn't read the pytrends documentation properly and it is possible to get the topic id:

from pytrends.request import TrendReq
pytrends = TrendReq(hl='en-US', tz=360)
suggs = pytrends.suggestions("iron")
print(suggs)

[{'mid': '/m/025rw19', 'title': 'Iron', 'type': 'Chemical element'},
 {'mid': '/m/04jphh9', 'title': 'Clothes iron', 'type': 'Topic'},
 {'mid': '/m/0b6l369', 'title': 'Loha', 'type': '1987 film'},
 {'mid': '/m/03cld36', 'title': 'Iron', 'type': 'Golf'},
 {'mid': '/m/0281ql7', 'title': 'Ferric', 'type': 'III'}]

From the above, it is easy to extract the topic id.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM