CURL奇怪问题

去圣西罗-为尤文喝彩 2012-11-21 12:17:49
碰到一个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;
...全文
186 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
ok,以后遇到了在解决,感谢。
xuzuning 2012-11-21
  • 打赏
  • 举报
回复
$matches[1][0] = str_replace('amp;', '', $matches[1][0]); curl_setopt($webch, CURLOPT_URL,$matches[1][0]);
xuzuning 2012-11-21
  • 打赏
  • 举报
回复
我没有什么经验,只是看到二次curl的url中多了“amp” 于是删掉就好了
  • 打赏
  • 举报
回复
老大,以你的经验,除了amp;以为还有什么符号会产生影响?

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧