碰到一个CURL的奇怪问题,从某网站上获取有一个URL地址,放到另一个CURL里抓取,居然是空的。如果把这个URL手动粘贴("http://www.napolimagazine.com.cn/?action=read&idnotizia=157004"),则可以获取相应的网页代码。检查了老半天都没解决。如果把`http://news.alot.com/?pr=smpl&f=1&q=napolimagazine&order=date&page=0`里的“napolimagazine”换成别的关键字,有时则可以获得结果。求解决方法。
header("Content-type: text/html; charset=utf-8");
$rch1 = curl_init();
curl_setopt($rch1, CURLOPT_URL, 'http://news.alot.com/?pr=smpl&f=1&q=napolimagazine&order=date&page=0');
curl_setopt($rch1, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($rch1, CURLOPT_COOKIE, "gl=IT;hl=it;nr=1;histEnable=0;suggEnable=1");
$rhtmls1 = curl_exec($rch1);
curl_close($rch1);
preg_match_all ("/<a class=\"algoTitle\" href=\"([^\"]+)\"[^<>]*>([^<>]+)<\/a>/i", $rhtmls1, $matches);
echo $matches[1][0];
$webch = curl_init();
curl_setopt($webch, CURLOPT_URL,$matches[1][0]);
//curl_setopt($webch, CURLOPT_URL,"http://www.napolimagazine.com.cn/?action=read&idnotizia=157004");
curl_setopt($webch, CURLOPT_RETURNTRANSFER, 1);
$htmls = curl_exec($webch);
curl_close($webch);
echo $htmls;