Allows simple interface for automating downloading of reports from Google Trends.
Only good until Google changes their backend again :-P. When that happens feel free to contribute!
Looking for maintainers! Please open an issue with a method of contacting you if you're interested.
For example US CST is '360' (note NOT -360, Google uses timezone this way...)
proxies
https proxies Google passed ONLY
list ['https://34.203.233.13:80','https://35.201.123.31:880', ..., ...]
retries
number of retries total/connect/read all represented by one scalar
backoff_factor
A backoff factor to apply between attempts after the second try (most errors are resolved immediately by a second try without a delay). urllib3 will sleep for: {backoff factor} * (2 ^ ({number of total retries} - 1)) seconds. If the backoff_factor is 0.1, then sleep() will sleep for [0.0s, 0.2s, 0.4s, …] between retries. It will never be longer than Retry.BACKOFF_MAX. By default, backoff is disabled (set to 0).
requests_args
A dict with additional parameters to pass along to the underlying requests library, for example verify=False to ignore SSL errors
Note: the parameter hl specifies host language for accessing Google Trends.
Note: only https proxies will work, and you need to add the port number after the proxy ip address
Interest Over Time: returns historical, indexed data for when the keyword was searched most as shown on Google Trends' Interest Over Time section.
Historical Hourly Interest: returns historical, indexed, hourly data for when the keyword was searched most as shown on Google Trends' Interest Over Time section. It sends multiple requests to Google, each retrieving one week of hourly data. It seems like this would be the only way to get historical, hourly data.
Interest by Region: returns data for where the keyword is most searched as shown on Google Trends' Interest by Region section.
Related Topics: returns data for the related keywords to a provided keyword shown on Google Trends' Related Topics section.
Related Queries: returns data for the related keywords to a provided keyword shown on Google Trends' Related Queries section.
Trending Searches: returns data for latest trending searches shown on Google Trends' Trending Searches section.
Top Charts: returns the data for a given topic shown in Google Trends' Top Charts section.
Suggestions: returns a list of additional suggested keywords that can be used to refine a trend search.
Up to five terms in a list: ['Pizza', 'Italian', 'Spaghetti', 'Breadsticks', 'Sausage']
Advanced Keywords
When using Google Trends dashboard Google may provide suggested narrowed search terms.
For example "iron" will have a drop down of "Iron Chemical Element, Iron Cross, Iron Man, etc".
Find the encoded topic by using the get_suggestions() function and choose the most relevant one for you.
For example: https://www.google.com/trends/explore#q=%2Fm%2F025rw19&cmpt=q
"/m/025rw19" is the topic "Iron Chemical Element" to use this with pytrends
You can also use pytrends.suggestions() to automate this.
cat
Category to narrow results
Find available categories by inspecting the url when manually using Google Trends. The category starts after cat= and ends before the next & or view this wiki page containing all available categories
For example: "https://www.google.com/trends/explore#q=pizza&cat=71"
'71' is the category
Defaults to no category
geo
Two letter country abbreviation
For example United States is 'US'
Defaults to World
More detail available for States/Provinces by specifying additional abbreviations
Google may change aggregation level for items with very large or very small search volume
Rate Limit is not publicly known, let me know if you have a consistent estimate
One user reports that 1,400 sequential requests of a 4 hours timeframe got them to the limit. (Replicated on 2 networks)
It has been tested, and 60 seconds of sleep between requests (successful or not) appears to be the correct amount once you reach the limit.
For certain configurations the dependency lib certifi requires the environment variable REQUESTS_CA_BUNDLE to be explicitly set and exported. This variable must contain the path where the ca-certificates are saved or a SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] error is given at runtime.
Credits
Major JSON revision ideas taken from pat310's JavaScript library
请发表评论