Local Google Results Scraper - PHP Class Download



This is a PHP class that allows you to scrape localized Google results from any city, country and state in the world which Google supports.

Developers can use this class to implement SERP tracking and testing for multiple locations.

Features

  • Get the titles, descriptions, and URLs of Google search results
  • Scrape multiple pages
  • Disable Google’s automatic location detection & allows you to set the location.
  • Doesn’t use a DOM (light on CPU)
  • Supports all google domains (google.com, google.com.au, etc)
  • Includes methods to search for/list compatible locations and languages

How does it work?

Google provides a tool for its AdWords users that lets them preview their ad on the search results for a location of their choosing.

However, there’s no scrapers for this tool, because Google encrypted the data necessary to override and set the location. This class implements a method to reproduce that encryption.

Less blocks

Through my personal testing, I have found that:

  • Google blocks are per-domain (being blocked on google.com doesn’t mean you’re blocked on google.com.au)
  • Blocks are more likely when searching with operators like “inurl” and “intext”

This class does its best to trick Google into thinking you’re just a normal AdWords user, as long as you don’t spam or search things like “inurl” and “intext”.

Code samples

See the screenshots and the documentation for example code.

Included examples

This class comes with four working PHP examples:

  1. Scraping results from Google into an array
  2. Setting the search location
  3. Testing a website’s SERP
  4. An example form to search for a location and get the results of a keyword.

PSR-4

If you need PSR-4 compliant code, there is a PSR-4 (composer-ready) version of the class included.

Locations

To see a full list of supported locations, see the Google Geographical Targeting page.

Requirements

This class requires PHP 5.4+ and the CURL extension must be enabled. That’s all!