Saturday, March 30, 2024

How to Scrape Search Results in Seconds with Python


Scraping Google search results can be a breeze with the help of a scraping API like ZenRows. In this example, I'll demonstrate how to scrape search results in the US for the term "iPhone" using ZenRows, although other options like SerpAPI, SerpDog, or SearchAPI.io work just as effectively.

First, you'll need to make a call to the scraping API, substituting your own API Key and providing the country as US, and the search query URL as https://www.google.com/search?q=iphone:

https://api.zenrows.com/v1/?apikey=YOUR_KEY&url=https%3A%2F%2Fwww.google.com%2Fsearch%3Fq%3Diphone&premium_proxy=true&proxy_country=us&autoparse=true


The API will return the results in JSON format, neatly organized for easy retrieval. Here's a simplified example:

{

  "aproximate_results": "13160000000",

  "organic_results": [

    {

      "description": "Discover the innovative world of Apple and shop everything iPhone, iPad, Apple Watch, Mac, and Apple TV, plus explore accessories, entertainment, ...",

      "displayed_link": "https://www.apple.com",

      "domain": "https://www.apple.com",

      "link": "https://www.apple.com/",

      "ratings": null,

      "summary_points": "",

      "title": "Apple"

    },

    {

      "description": "The iPhone is a line of smartphones produced by Apple Inc. that use Apple's own iOS mobile operating system. The first-generation iPhone was announced by ...",

      "displayed_link": "https://en.wikipedia.org › wiki › IPhone",

      "domain": "https://en.wikipedia.org",

      "link": "https://en.wikipedia.org/wiki/IPhone",

      "ratings": null,

      "summary_points": "",

      "title": "iPhone"

    },


    ...

}


From here, you can easily extract and track the search results as needed.

In conclusion, utilizing a SERP Scraping API like ZenRows offers the simplest solution for scraping Google results. With the flexibility to call the API from any programming language and the absence of maintaining expensive infrastructure, it's a convenient and cost-effective option for keeping up with Google's ever-changing landscape.

0 comments:

Post a Comment