Umair Ayub
Umair Ayub

Reputation: 21351

Scrape business listing content from google search

I am developing a simple PHP app which takes business name, business address and business phone from user and then checks if that business is listed in Google or not and

Also compares the business name, address and phone returned by Google against the search terms.

The result I want to display whether the information found in Google is accurate or whether something is different or missing. Something similar as this site does

What I have tried:

I have tried to scrape page with phpQuery library but it does not include that part(which is circled in image below).

$buss_name = $_GET['business_name'];

$link = "https://www.google.com/search?q=" . urlencode($buss_name) . "&rct=j";

$resp_html = file_get_contents($link, false);
$resp_html = phpQuery::newDocumentHTML($resp_html);
echo $resp_html;
echo pq("div.kno-ecr-pt.kno-fb-ctx._hdf",$resp_html)->text();

Reason is that it is loaded via some sort of AJAX call.

I also tried this web service by google

http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=don%20jayne%20&%20assoc

But this also do not include that part I require.

Long story short >>> Please tell me is there any API or whatever is available which checks for a business listed on Google or not?

enter image description here

Upvotes: 1

Views: 2757

Answers (1)

Miguel Costa
Miguel Costa

Reputation: 399

probably you wont need this anymore but I will reply your post just for future reference.

One of the ways to check if a business is on google or not, is to check the google places api (documentation). You can preform a search and then check the results for the business you are looking for. Something like this:

$params = array(
          'query' => 'mindseo',
          'key' => "XXXXXXXXXXXXXXXXXXX");
$service_url = 'https://maps.googleapis.com/maps/api/place/textsearch/json';

//do the request
$placesSearch = request( $service_url, $params );

//print the result
print_r($placesSearch); 

//loop the results 
if ( count( $placesSearch['results'] ) >= 1 ) {
  $params = array(
          'placeid' => $placesSearch['results'][0]['place_id'],
          'key' => "AIzaSyAc73-uGCLLIuN3Bb2idOwRbLBzoaTmPHI");

  $service_url = 'https://maps.googleapis.com/maps/api/place/details/json';
  $placeData = request( $service_url, $params  );

  //echo the place data
  echo '//Place ID#'.$params['placeid'].' DATA -----------------------';
  print_r($placeData);
}

//function to make the request
function request( $googleApiUrl, $params) {
  $dataOut = array();

  $url = $googleApiUrl . '?' . http_build_query($params);

  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

  $dataOut = json_decode(curl_exec($ch), true);

  curl_close($ch);    
  return $dataOut;
}

Upvotes: 1

Related Questions