duanguai2781 2015-07-29 17:23
浏览 12

从谷歌搜索刮取商业列表内容

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

  • 写回答

1条回答 默认 最新

  • douquqiang1513 2016-06-29 15:59
    关注

    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;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度