file_get_contents 无法打开流:HTTP 请求失败!HTTP/1.1 500 内部 >服务器错误 [英] file_get_contents failed to open stream: HTTP request failed! HTTP/1.1 500 Internal > Server Error in

查看:46
本文介绍了file_get_contents 无法打开流:HTTP 请求失败!HTTP/1.1 500 内部 >服务器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到很多与我的问题相符的问题.但他们都没有提供任何可行的解决方案.因此,我需要简单的解决方案,而不是制作复杂的功能.请我不要卷曲.我已经对这段代码做了很多工作.

I see many questions matching to my issue. But none of them is providing any workable solution. so instead of making complex functionality i need simple solution. Please I dont' want cURL. I've already done a lot with this code.

我正在处理一个抓取项目,需要从 ebay 加载产品修订的内容.

I'm working on a scraping project and need to load the contents of product revisions from ebay.

我正在使用 PHP 函数

I am using PHP function

file_get_contents();

这是我遇到麻烦的网址.

Here is the URL i'm troubling with.

https://cgi.ebay.com/ws/eBayISAPI.dll?ViewItemRevisionDetails&item=272908801183

这个file_get_contents();在不同的 URL 上工作得很好,但不知道为什么不这样做.

this file_get_contents(); is working perfectly fine on different URLs but don't know why not on this.

这是我正在使用的代码.

This is the code i'm using.

<?php
$html = file_get_contents('https://cgi.ebay.com/ws/eBayISAPI.dll?ViewItemRevisionDetails&item=272908801183');
echo $html;
?>

但我收到此错误..

警告:file_get_contents(https://cgi.ebay.com/ws/eBayISAPI.dll?ViewItemRevisionDetails&&item=272908801183):无法打开流:HTTP 请求失败!HTTP/1.1 500 内部服务器错误/Users/samz/Documents/projects/scraping/test.php第 3 行

Warning: file_get_contents(https://cgi.ebay.com/ws/eBayISAPI.dll?ViewItemRevisionDetails&&item=272908801183): failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error in /Users/samz/Documents/projects/scraping/test.php on line 3

推荐答案

file_get_contents(阅读蓝色矩形的提示)可以通过 php.ini 避免使用它.当您想从其他站点获取数据时,请改用 curl.http://php.net/manual/en/book.curl.php,有很多选项可以与 curl 一起使用,通过播放一些以下代码可以与您的 url 一起使用.

file_get_contents (read the tip on blue rectangle) can be easily blocked on server side through php.ini avoid using it. When you want to get data from an other site use curl instead. http://php.net/manual/en/book.curl.php, there are plenty of options that you can use with curl, by playing a bit the following code can work with your url.

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_URL,"https://cgi.ebay.com/ws/eBayISAPI.dll?ViewItemRevisionDetails&item=272908801183");
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.A.B.C Safari/525.13");
$data = curl_exec($ch);
curl_close($ch);

通过回显 $data 变量,您可以看到整个页面.

and by echoing the $data varible you can see the whole page.

echo $data;

您可以尝试使用 php DOM 方法解析页面中的数据并将它们转换为您想要的数据类型(对象类、数组等).

you can try parsing the data from the page by utilizing php DOM Methods and convert them to the data type you want (object class, array etc).

这篇关于file_get_contents 无法打开流:HTTP 请求失败!HTTP/1.1 500 内部 &gt;服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆