[英]PHP curl redirect moved permanently
I'm downloading blog posts for analysis and after 10 pages of results I'm getting a strange redirect to the site's homepage rather than to the 10th page of results. 我正在下载博客文章进行分析,结果显示10页后,我奇怪地重定向到网站的首页,而不是结果的第10页。 Going to the 10th page in my browser works just fine.
在浏览器中转到第10页就可以了。
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, "http://www.russellmoore.com/category/article/page/10");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$html = curl_exec($ch);
$status = curl_getinfo($ch);
print_r($status);
Executing this code redirects my script to http://www.russellmoore.com/ . 执行此代码会将我的脚本重定向到http://www.russellmoore.com/ 。
As Daren pointed out, removing the user agent worked. 正如Daren指出的那样,删除用户代理是可行的。 However, because another blog I was downloading from required a user agent, I changed it to:
但是,由于我要从中下载的另一个博客需要用户代理,因此将其更改为:
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0');
This solution worked for both blogs. 该解决方案适用于两个博客。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.