This example demonstrates how to scrape Google Trends data using the forEachElement and mergeContext step types to:
{
"startUrl": "https://trends.google.com/trending?geo=EG&category=20&hours=24&sort=title",
"steps": [
// Initial setup steps (cookie acceptance, page loading, etc.)
{
"type": "extract",
"name": "trendsData",
"selector": "table.enOdEe-wZVHld-zg7Cn",
"description": "Extract initial trends table data",
"fields": {
"trends": {
"selector": "tr.enOdEe-wZVHld-xMbwt",
"type": "css",
"multiple": true,
"fields": {
"title": { "selector": ".mZ3RIc", "type": "css" },
"searchVolume": { "selector": ".lqv0Cb", "type": "css" },
"growth": { "selector": ".TXt85b", "type": "css" },
"relatedQueries": {
"selector": ".k36WW div button",
"type": "css",
"multiple": true,
"attribute": "data-term"
}
}
}
}
},
// The key forEachElement section that processes each trend
{
"type": "forEachElement",
"selector": "tr.enOdEe-wZVHld-xMbwt",
"description": "Process each trend row to get detailed data",
"maxIterations": 50,
"elementSteps": [
{
"type": "click",
"selector": ".mZ3RIc",
"description": "Click trend title to open details panel"
},
{
"type": "wait",
"value": ".EMz5P .k44Spe",
"timeout": 15000,
"description": "Wait for panel content to load"
},
{
"type": "extract",
"name": "panelData",
"selector": ".EMz5P",
"description": "Extract panel details",
"fields": {
"news": {
"selector": ".jDtQ5 .xZCHj",
"type": "css",
"multiple": true,
"fields": {
"title": { "selector": ".QbLC8c", "type": "css" },
"sourceInfo": { "selector": ".pojp0c", "type": "css" },
"url": { "attribute": "href" }
}
},
"relatedQueries": {
"selector": ".HLcRPe button",
"type": "css",
"multiple": true,
"attribute": "data-term"
}
}
},
// Critical mergeContext step that combines the data
{
"type": "mergeContext",
"source": "panelData",
"target": "trendsData.trends[]",
"mergeStrategy": {
"news": "overwrite",
"relatedQueries": "union"
},
"description": "Merge panel data back into main trends array"
},
{
"type": "click",
"selector": ".EMz5P button[aria-label='Close']",
"description": "Close panel",
"optional": true
},
{
"type": "wait",
"value": 500,
"description": "Brief pause before next iteration"
}
]
}
]
}
maxIterations to limit processingelementStepsoverwrite for news (replaces existing data)union for related queries (combines with existing data)See the complete configuration file: googletrendingnow-config.json
Selectors may need updating if Google Trends changes its UI
The mergeContext step is critical for combining data from multiple interactions