Google Hurdaya yapmak çok kolay bir şeydir. Eğer ilk 30 sonuç daha fazla ihtiyaç yoksa (diğerleri önerilen gibi) Ancak, daha sonra search API tercih edilir. Aksi takdirde, burada bazı örnek kod. Ben bu yüzden olduğu gibi tamamen işlevsel olmayabilir istimal sınıfların bir çiftin bu yırtık ettik, ama fikir almalısınız.
function queryToUrl($query, $start=null, $perPage=100, $country="US") {
return "http://www.google.com/search?" . $this->_helpers->url->buildQuery(array(
// Query
"q" => urlencode($query),
// Country (geolocation presumably)
"gl" => $country,
// Start offset
"start" => $start,
// Number of result to a page
"num" => $perPage
), true);
}
// Find first 100 result for "pizza" in Canada
$ch = curl_init(queryToUrl("pizza", 0, 100, "CA"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $this->getUserAgent(/*$proxyIp*/));
curl_setopt($ch, CURLOPT_MAXREDIRS, 4);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
Not: $this->_helpers->url->buildQuery() boş parametreleri düşecek dışında http_build_query a> ile aynıdır.