谷歌搜索结果与PHP [英] Google search results with php
本文介绍了谷歌搜索结果与PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下php脚本从Google获取搜索结果。
I'm using the following php script to get search results from Google.
include("simple_html_dom.php");
include("random-user-agent.php");
$query = 'facebook';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://www.google.com/search?q='.$query.'');
#curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($curl, CURLOPT_USERAGENT,random_user_agent());
$str = curl_exec($curl);
curl_close($curl);
$html= str_get_html($str);
$i = 0;
foreach($html->find('li[class=g]') as $element) {
foreach($element->find('h3') as $item)
{
$title[$i] = ''.$item->plaintext.'' ;
}
$i++;
}
print_r($title);
当此脚本在cronjob中运行(睡眠时间为5秒)时,我收到了Google的警告,填写验证码(显而易见)。我一直认为使用curl和随机用户代理可以避免这种情况。正确的解决方案是什么?
When this script runs in a cronjob (with 5 sec sleep) I receive a warning from Google and have to fill in a captcha (obvious). I always thought that using curl and a random user agent can avoid this. What is the correct solution?
推荐答案
避免验证码的更好方法是将每个请求的睡眠间隔设置为3-6秒。
A better way to avoid captcha is to set a randomized sleep between 3-6 seconds per request.
最好的解决方案是使用代理。
Best solution is to use proxies.
这篇关于谷歌搜索结果与PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文