我尝试抓一些关键字,但是我收到了这个错误。 我无法弄明白,当我从Curl加载时,我认为问题出在Dom上。我尝试了不同的方法,希望你能帮助我。
只有Dom它可以工作,但我需要使用卷曲。
include("simple_html_dom.php");
$lines = file('key.txt', FILE_SKIP_EMPTY_LINES);
foreach ($lines as $key)
{
$bla= ucwords($key);
$in = str_replace(' ','+',$bla);
$ch = curl_init();
$url = 'http://www.google.com/search?hl=en&tbo=d&site=&source=hp&q='.$in.'&oq='.$in.'&num=20';
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$html = curl_exec($ch);
curl_close($ch);
$dom = new simple_html_dom();
$html = str_get_html($html);
@$dom->load($html);
$i=0;
$linkObjs = $html->find('h3.r a');
$content = array();
foreach ($linkObjs as $linkObj)
{
$title = trim($linkObj->plaintext);
$descr = $html->find('span.st',$i);
$i++;
$content[] = strip_tags($title.$descr);
}
var_dump($content);
}