您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息
三六零分类信息网 > 怒江分类信息网,免费分类信息发布

PHP curl实现抓取302跳转后页面的示例

2024/5/9 18:31:05发布2次查看
php的curl正常抓取页面程序如下:
$url = 'http://www.baidu.com'; $ch = curl_init(); curl_setopt($ch, curlopt_url, $url); curl_setopt($ch, curlopt_verbose, true); curl_setopt($ch, curlopt_header, true); curl_setopt($ch, curlopt_nobody, true); curl_setopt($ch, curlopt_customrequest, 'get'); curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_timeout, 20); curl_setopt($ch, curlopt_autoreferer, true); curl_setopt($ch, curlopt_followlocation, true); $ret = curl_exec($ch); $info = curl_getinfo($ch); curl_close($ch);
如果你抓取到的是302状态,是因为再抓取的过程中,有的跳转需要给下一个链接传递参数,而下一个链接同时也设置了如果没接收到相应的参数是为非法访问。
curl_setopt($curl, curlopt_customrequest, 'get');
显示就应该正常了。
上面用来抓取功能,几乎应该没问题的。你可以查一下curlopt_customrequest相关资料。
使用一个自定义的请求信息来代替”get”或”head”作为http请求。这对于执行”delete” 或者其他更隐蔽的http请求。有效值如”get”,”post”,”connect”等等。也就是说,不要在这里输入整个http请求。例如输入”get /index.html http/1.0\r\n\r\n”是不正确的。
更多php curl实现抓取302跳转后页面的示例。
怒江分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录