脚本宝典收集整理的这篇文章主要介绍了php – file_get_contents()给我403禁止,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。@H_777_0@ 我有一个合作伙伴,为我创造了一些内容来刮.
我试过使用stream_context_create,但这不是帮助 – 这可能是因为我不知道应该在那里.
1)有没有办法刮刮数据?
2)如果没有,如果合作伙伴不允许配置服务器让我访问,那我该怎么办?
我试过使用的代码:
$opts = array( 'http'=>array( 'user_agent' => 'My company name','method'=>"GET",'header'=> implode("\r\n",array( 'Content-tyPE: text/plain;' )) ) ); $context = stream_context_create($opts); //Get header content $_header = file_get_contents($partner_url,false,$context);
很难说出什么阻挡你,很可能是某种阻止刮擦的东西.如果您的合作伙伴可以访问其Web服务器设置,可能有助于确定.
您可以做的是通过设置用户代理头来“伪造Web浏览器”,以模拟标准Web浏览器.
// create curl resource $ch = curl_init(); // set url curl_setopt($ch,CURLOPT_URL,"example.COM"); //return the transfer as a string curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); 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'); // $output contains the output string $output = curl_exec($ch); // close curl resource to free up system resources curl_close($ch);
以上是脚本宝典为你收集整理的php – file_get_contents()给我403禁止全部内容,希望文章能够帮你解决php – file_get_contents()给我403禁止所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。