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.
- 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.
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”.
See the screenshots and the documentation for example code.
This class comes with four working PHP examples:
If you need PSR-4 compliant code, there is a PSR-4 (composer-ready) version of the class included.
To see a full list of supported locations, see the Google Geographical Targeting page.
This class requires PHP 5.4+ and the CURL extension must be enabled. That’s all!