Turn Google's "Trending now" into a daily content-ideas list (Python)
Writers and marketers often check Google Trends by hand each morning. The "Trending now" list is the interesting part, and it's also what's hardest to get as data. This is how I pull it for a few countries and keep only the topics worth a post. Get today's trends I use a hosted Actor I maintain on Apify ( Google Trending Now ). With pip install apify-client pandas : from apify_client import…
Writers and marketers frequently examine Google Trends manually each morning. The "Trending now" list is fascinating, but extracting it as data can be challenging. This is how I retrieve it for a few countries and retain only the subjects suitable for a post. I utilize a hosted Actor I maintain on Apify ( Google Trending Now ). With pip install apify-client pandas, I import the necessary libraries:
from apify_client import ApifyClient
import pandas as pd
I then establish a connection using my Apify token:
client = ApifyClient ( "YOUR_APIFY_TOKEN" )
Next, I call the Actor with the desired parameters:
run = client.actor ( "fjordlabs/google-trending-now" ).call ( run_input = { "geos" : [ "US" , "GB" , "DE" , "DK" ] , "includeNews" : True , "minTraffic" : 5000 , } )
The retrieved data is converted into a pandas DataFrame for easier manipulation:
df = pd.DataFrame ( client.dataset ( run [ "defaultDatasetId" ] ).iterate_items ( ) )
I display the first 15 rows of the DataFrame, including the geo location, rank, title, approximate traffic, and start time:
print ( df [ [ "geo" , "rank" , "title" , "approxTraffic" , "startedAt" ] ] . head ( 15 ) )
To filter out small topics and reduce costs, I set a minimum traffic threshold using minTraffic:
minTraffic drops small topics before they're returned (and billed).
For each row in the DataFrame, I extract the title and check if it contains any of the specified keywords:
keywords = [ "ai" , "phone" , "election" , "game" , "energy" ]
mask = df [ "title" ] . str . lower ( ) . str . contains ( "|" . join ( keywords ) )
I then sort the filtered data by approximate traffic in descending order and save the results to a CSV file:
ideas = df [ mask ] . sort_values ( "approxTrafficNumber" , ascending = False )
ideas [ [ "geo" , "title" , "approxTraffic" , "exploreUrl" ] ] . to_csv ( "ideas.csv" , index = False )
Topics that appear in multiple countries on the same day are often the most reliable choices. To ensure the process runs automatically each day, I schedule the Actor and integrate Apify's email, Slack, or webhook features to send the generated ideas.csv file. As a bonus, each trend costs only $0.001, making it cost-effective for 4 countries with approximately 20 topics each, which translates to around 8 cents a day before the traffic filter.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to