Code

Local Google Results Scraper - PHP Class

Local Google Results Scraper - PHP Class

(3) 5.00 stars
134 Sales

PHP class to scrape local search results from Google. Customize the location, language, domain, and device type.

Please note that this is not an application. It is only code, and you must know PHP in order to use it.

Features

  • Scrape local search results from over 92,000 locations worldwide.
  • Disables & overrides Google’s automatic location detection.
  • Scrape unlimited pages.
  • Set the language for search results.
  • Easily switch between desktop, tablet, or mobile.
  • Use any Google domain (google.com, google.nl, etc)
  • Proxy support – with optional user/pass authentication
  • Fast & lightweight parsing – doesn’t use a DOM.
  • Composer-ready (PSR-4) version included.

API Documentation

Please refer to the Live Preview to see full API documentation and more code examples. Or you can search the available locations.

Example code

<?php
    require "class.Google.php";

    $google = new GoogleSearch();
    $google->setLocation("new york");
    $google->setQuery("nearby restaurants");
    $google->setDevice("mobile"); // optional
    $google->setLanguage(new Language("es")); // optional
    $google->setProxy("123.211.1.13:8080", "user:pass"); // optional

    $page1 = $google->next();
    $page2 = $google->next();

    while ($result = $page1->fetch_array()) {
        $title = $result["title"];
        $description = $result["description"];
        $site = $result["site"];
        $domain = $result["domain"];

        echo $title . " - ";
        echo $domain . "<br>";
    }
?>

Requirements

  • PHP 5.4 +
  • CURL

Changelog

Version 1.12 (April 01, 2020)
- Schema update (see below).

Version 1.09 (Feb 11, 2020)
- Schema update (see below).

Version 1.08 (Feb 01, 2020)
- Schema update (see below).

Version 1.07 (Sep 23, 2019)
- You can now set location to null (or not specify it) to let Google automatically detect your location.

Version 1.06 (Jun 13, 2019)
- Schema update (see below).

Version 1.04 (Oct 6, 2016)
- Fixed first item in search results being skipped when calling fetch_array or fetch_object.
- Updated Google Maps snippets to match Google's latest layout changes.

Version 1.03 (Aug 2, 2016)
- Added new location property to Google Place records, containing the place's address.
- Fixed Google redirection from google.com to local country.
- Fixed rare missing items from the search results.
- Fixed referrer not being set properly when connecting to Google.

Version 1.02 (Aug 1, 2016)
- Added new "url" property to search results, to get the absolute URL of each result

Version 1.01
- New techiehut documentation.
- Fixed some domain names not parsing correctly.
- Added new Location and Language classes.
- Updated composer (PSR-4) code to follow specifications.

Version 1.0
- Initial release

What is a schema update?

This script uses schemas to parse search result pages rather than relying on DOM parsing. This makes the class exceptionally faster and more memory-efficient. However, it also means that the class needs to be updated whenever Google changes certain parts of their HTML, which is what I call a “schema update.”

by
by
by
by
by
by