Google arama: total sonuçları için PHP sonuçlar sayfasını Scrape

4 Cevap

Buldum arama sonuçlarının sayısını çekin PHP ile Google arama sonuçları sayfasında kazımak mümkün mü?

Bu yüzden bunu nasıl yapıyor hakkında gitmek istiyorum?

Teşekkürler

4 Cevap

http://www.phpclasses.org/browse/package/3924.html: Bu PHP sınıfı yapar

"This class can be used to get the total number of results for given Google search query.

It accesses the Google search site to perform a query for given search terms.

The class parses the results page and extract the total number of results that the given search query returned."

kullanarak bu deneyin phpsimplehtmlparser

$search_query = 'google';
$url = sprintf('http://www.google.com/search?q=%s', $search_query);
$html = file_get_html($url);
$results = $html->find('#resultStats/b', 2)->innertext;

echo sprintf('Google found %s results for "%s"', $results, $search_query);

You'll need a bunch of proxies depending on the number of requests you plan to send. You can send about 500 requests per day and IP/proxy without causing trouble or getting detected.

Sen google-rütbe-checker.squabbel.com makalede okumalısınız, PHP içinde tam özellikli bir kazıyıcı içerir. Bu kazıyıcı kullanın ihtiyaçlarına değiştirebilir ve anahtar kelimeler için toplam hits bilgi almak için phpsimplehtmlparser kodunu (diğer cevap) ekleyin.

I suggest the use of libCURL for accessing Google itself. You will have a LOT more options than using a more simple API, you'll not have much fun with file_get_html() or similar php internal functions as Google would block your script very soon.

Böyle bir şey:

  curl_setopt ($ch, CURLOPT_HEADER, 0);
  curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
  curl_setopt ($ch, CURLOPT_RETURNTRANSFER , 1);
  $curl_proxy = "$IP:$PORT";
  curl_setopt($ch, CURLOPT_PROXY, $curl_proxy);
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
  curl_setopt($ch, CURLOPT_TIMEOUT, 20);
  curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.0; en; rv:1.9.0.4) Gecko/2009011913 Firefox/3.0.6");
  $url = sprintf('http://www.google.com/search?q=%s', $keyword);
  curl_setopt ($ch, CURLOPT_URL, $url);
  $htmdata = curl_exec ($ch);

Şimdi sadece $ htmldata verileri kapmak için regex () / substr () / strstr () kullanın

Ben google arama ismimin toplam sonuçlarını öğrenmek için bu php komut dosyası kullanıyorum.

<?php
$homepage = file_get_contents('http://www.google.co.in/search?ix=nh&sourceid=chrome&ie=UTF-8&q=Mohit+dabas');
preg_match('/(About )?([\d,]+) result/si', $homepage, $p) ;
echo $p[0];
?>

fark edilecek ana şey yukarıda tanımlanan yolunu parametre '& q' olduğunu

Tarayıcı ona '+' eklendi yüzden benim adım boşluk içeren

Ur sorgu bazı özel içeren Yani eğer ur sorgusu (yani & q) parametreleri kontrol etmelisiniz

gibi karakter,:.,% vb sonra onlar tarayıcı tarafından tedavi edilir nasıl dikkat edilmeli ve

parametreler ACC değiştirin. Lütfen ihtiyaç int komut için.

kötü İngilizce için srry