Google Search via SerpAPI

Search Google via SerpAPI and fetch clean text from top N sites

Overview

This node performs a Google search using the SerpAPI service and retrieves clean text snippets from the top N resulting websites. It is useful when you want to programmatically gather summarized content or insights from multiple web pages related to a search query without manually visiting each link.

Common scenarios include:

  • Research automation: Quickly gather information on a topic by searching Google and extracting readable text from top results.
  • Content summarization: Fetch key textual content from multiple sources for further processing or analysis.
  • Data enrichment: Enhance datasets with relevant web content based on search queries.

For example, you could input the query "What is quantum computing?" and retrieve the top 5 Google search results along with cleaned text excerpts from those pages.

Properties

Name Meaning
Search Query The search phrase or question to look up on Google via SerpAPI.
Number of Results How many top search results to retrieve and process (between 1 and 10).
SerpAPI Key Your API key credential to authenticate requests to the SerpAPI service at serpapi.com.

Output

The node outputs an array with one item per execution. Each item's json field contains:

  • query: The original search query string.
  • links: An array of URLs representing the top N Google search results.
  • texts: An array of strings where each string is cleaned text extracted from the corresponding URL's webpage. If fetching a page fails, the string will contain an error message describing the failure.

No binary data output is produced by this node.

Dependencies

  • Requires an active SerpAPI account and a valid API key to perform Google searches.
  • Uses HTTP requests to SerpAPI and to the retrieved URLs.
  • Relies on the axios library for HTTP calls and cheerio for HTML parsing and cleaning.
  • The node sets a custom User-Agent header "Mozilla/5.0 (n8n-bot)" when fetching webpage content.
  • Timeout for webpage fetches is set to 8 seconds.

Troubleshooting

  • No results returned from SerpAPI: This error occurs if the search query yields no organic results. Verify the query is valid and that your SerpAPI key has sufficient quota.
  • Failed to fetch [URL]: Indicates a problem retrieving or parsing a specific webpage. Possible causes include network issues, site blocking bots, or slow responses exceeding the timeout. Consider increasing timeout or checking network access.
  • API key errors: If authentication to SerpAPI fails, ensure the API key is correct and active.
  • Rate limits: SerpAPI enforces rate limits; hitting these may cause errors. Monitor usage and upgrade your plan if needed.
  • To continue processing other items despite errors, enable the node’s “Continue On Fail” option.

Links and References

Discussion