Я пытаюсь очистить результаты поиска Google с помощью PHP.
Я пробовал использовать @file_get_contents (http://www.google.com/search?hl=en&q=test), но это не сработало. Работает только с http://www.google.com .
Вместо этого я пробовал использовать curl. Вот моя функция:
function my_fetch($url,$user_agent='Mozilla/4.0 (compatible; MSIE
5.01; Windows NT 5.0)') {
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_REFERER, 'http://www.google.com/');
$result = curl_exec ($ch);
curl_close ($ch);
return $result; }
$googleContent = my_fetch("http://www.google.com/search?hl=en&q=test");
echo $googleContent;
Результат:
302 Moved
The document has moved here.
Со ссылкой сюда: http://www.google.com/sorry/?continue=http://www.google.com/search%3Fhl % 3Den% 26q% 3Dtest
Есть ли способ сканировать результаты поиска с помощью PHP без необходимости изучения API?