Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用curl阅读棘手的rss_Php_Curl_Rss_Rss Reader - Fatal编程技术网

Php 使用curl阅读棘手的rss

Php 使用curl阅读棘手的rss,php,curl,rss,rss-reader,Php,Curl,Rss,Rss Reader,有没有人知道热可以让这个提要以卷曲的方式阅读? 我很明显错过了一些curl conf,但我对这方面还不熟悉,通常是做JS function url_get_contents ($Url) { if (!function_exists('curl_init')){ die('CURL is not installed!'); } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $Url); curl_setopt($ch, CURLOP

有没有人知道热可以让这个提要以卷曲的方式阅读? 我很明显错过了一些curl conf,但我对这方面还不熟悉,通常是做JS

function url_get_contents ($Url) {

if (!function_exists('curl_init')){ 
    die('CURL is not installed!');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
调用脚本,如下所示

echo url_get_contents('http://maxhire.net/cp/?EA5E6F361D4364703D044F72');

不适用于此订阅源,也适用于任何其他订阅源,例如http://x ml.corriereobjects.it/rss/homepage.xml

此网站似乎希望有一个名为AspXAutoDetectCookiesSupport的cookie,如果找不到它,它会将您重定向到某个cookie检测页面,并且它会陷入一个循环:

> curl -I -L http://maxhire.net/cp/?EA5E6F361D4364703D044F72
HTTP/1.1 302 Found
Date: Fri, 23 Aug 2013 23:10:55 GMT
Server: Microsoft-IIS/6.0
P3P: CP="CAO PSA OUR"
X-Powered-By: ASP.NET
X-AspNet-Version: 4.0.30319
Location: /cp/?EA5E6F361D4364703D044F72&AspxAutoDetectCookieSupport=1
Cache-Control: private
Content-Type: text/html; charset=utf-8
Content-Length: 180
Connection: Keep-Alive
Set-Cookie: AspxAutoDetectCookieSupport=1; path=/

HTTP/1.1 302 Found
Date: Fri, 23 Aug 2013 23:10:56 GMT
Server: Microsoft-IIS/6.0
P3P: CP="CAO PSA OUR"
X-Powered-By: ASP.NET
X-AspNet-Version: 4.0.30319
Location: /cp/?EA5E6F361D4364703D044F72&AspxAutoDetectCookieSupport=1
&AspxAutoDetectCookieSupport=1
Cache-Control: private
Content-Type: text/html; charset=utf-8
Content-Length: 214
Connection: Keep-Alive
Set-Cookie: AspxAutoDetectCookieSupport=1; path=/

HTTP/1.1 302 Found
Date: Fri, 23 Aug 2013 23:10:57 GMT
Server: Microsoft-IIS/6.0
P3P: CP="CAO PSA OUR"
X-Powered-By: ASP.NET
X-AspNet-Version: 4.0.30319
Location: /cp/?EA5E6F361D4364703D044F72&AspxAutoDetectCookieSupport=1
&AspxAutoDetectCookieSupport=1&AspxAutoDetectCookieSupport=1
Cache-Control: private
Content-Type: text/html; charset=utf-8
Content-Length: 248
Connection: Keep-Alive
Set-Cookie: AspxAutoDetectCookieSupport=1; path=/


^C
因此,您需要设置此cookie:AspxAutoDetectCookieSupport=1:

解决了第一个问题,又出现了另一个问题,如果您没有为用户代理设置值,它将向您发送此页面:

<html xmlns:atom="http://www.w3.org/2005/Atom">
<head><meta http-equiv="Content-Type" content="text/xml; charset=iso-8859-1" /><
title>
        Untitled Page
</title><link href="App_Themes/Default/Common.css" type="text/css" rel="styleshe
et" /><link href="App_Themes/Default/Container.css" type="text/css" rel="stylesh
eet" /><link href="App_Themes/Default/Content.css" type="text/css" rel="styleshe
et" /><link href="App_Themes/Default/Login.css" type="text/css" rel="stylesheet"
 /></head>
<body>
    <form name="form1" method="post" action="rssCurrentJobs.aspx?site=5E6F361D43
64703D044F72" id="form1">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTc2MTg4
NDc4NmRk" />

    <div>

    </div>
    </form>
</body>
</html>
完整代码:

function url_get_contents ($Url) {

    if (!function_exists('curl_init')){ 
        die('CURL is not installed!');
    }

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $Url);
    curl_setopt($ch, CURLOPT_POST, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_USERAGENT, "SomeUserAgent");
    curl_setopt($ch, CURLOPT_COOKIE, 'AspxAutoDetectCookieSupport=1');
    $output = curl_exec($ch);
    curl_close($ch);
    return $output;
}

此网站似乎期待一个名为AspxAutoDetectCookieSupport的cookie,如果找不到它,它会将您重定向到某个cookie检测页面,它将陷入循环:

> curl -I -L http://maxhire.net/cp/?EA5E6F361D4364703D044F72
HTTP/1.1 302 Found
Date: Fri, 23 Aug 2013 23:10:55 GMT
Server: Microsoft-IIS/6.0
P3P: CP="CAO PSA OUR"
X-Powered-By: ASP.NET
X-AspNet-Version: 4.0.30319
Location: /cp/?EA5E6F361D4364703D044F72&AspxAutoDetectCookieSupport=1
Cache-Control: private
Content-Type: text/html; charset=utf-8
Content-Length: 180
Connection: Keep-Alive
Set-Cookie: AspxAutoDetectCookieSupport=1; path=/

HTTP/1.1 302 Found
Date: Fri, 23 Aug 2013 23:10:56 GMT
Server: Microsoft-IIS/6.0
P3P: CP="CAO PSA OUR"
X-Powered-By: ASP.NET
X-AspNet-Version: 4.0.30319
Location: /cp/?EA5E6F361D4364703D044F72&AspxAutoDetectCookieSupport=1
&AspxAutoDetectCookieSupport=1
Cache-Control: private
Content-Type: text/html; charset=utf-8
Content-Length: 214
Connection: Keep-Alive
Set-Cookie: AspxAutoDetectCookieSupport=1; path=/

HTTP/1.1 302 Found
Date: Fri, 23 Aug 2013 23:10:57 GMT
Server: Microsoft-IIS/6.0
P3P: CP="CAO PSA OUR"
X-Powered-By: ASP.NET
X-AspNet-Version: 4.0.30319
Location: /cp/?EA5E6F361D4364703D044F72&AspxAutoDetectCookieSupport=1
&AspxAutoDetectCookieSupport=1&AspxAutoDetectCookieSupport=1
Cache-Control: private
Content-Type: text/html; charset=utf-8
Content-Length: 248
Connection: Keep-Alive
Set-Cookie: AspxAutoDetectCookieSupport=1; path=/


^C
因此,您需要设置此cookie:AspxAutoDetectCookieSupport=1:

解决了第一个问题,又出现了另一个问题,如果您没有为用户代理设置值,它将向您发送此页面:

<html xmlns:atom="http://www.w3.org/2005/Atom">
<head><meta http-equiv="Content-Type" content="text/xml; charset=iso-8859-1" /><
title>
        Untitled Page
</title><link href="App_Themes/Default/Common.css" type="text/css" rel="styleshe
et" /><link href="App_Themes/Default/Container.css" type="text/css" rel="stylesh
eet" /><link href="App_Themes/Default/Content.css" type="text/css" rel="styleshe
et" /><link href="App_Themes/Default/Login.css" type="text/css" rel="stylesheet"
 /></head>
<body>
    <form name="form1" method="post" action="rssCurrentJobs.aspx?site=5E6F361D43
64703D044F72" id="form1">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTc2MTg4
NDc4NmRk" />

    <div>

    </div>
    </form>
</body>
</html>
完整代码:

function url_get_contents ($Url) {

    if (!function_exists('curl_init')){ 
        die('CURL is not installed!');
    }

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $Url);
    curl_setopt($ch, CURLOPT_POST, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_USERAGENT, "SomeUserAgent");
    curl_setopt($ch, CURLOPT_COOKIE, 'AspxAutoDetectCookieSupport=1');
    $output = curl_exec($ch);
    curl_close($ch);
    return $output;
}

从技术上讲,您只需要文件\u获取\u内容'http://....,假设启用了PHP的allow_url_fopen。很可能feed正在进行UA和/或referer过滤,所以你必须更好地伪装成一个普通的浏览器。嗨,感谢您的评论文件,第一个选项是“获取内容”,但即使将“允许url”设置为“真”,此url也不起作用:-您假装是普通浏览器的暗示给了我一些想法,如“用户代理”。。。当然,如果有人知道这个解决方案是非常受欢迎的!!我是一个客户端的家伙-从技术上讲,您只需要文件\u获取\u内容'http://....,假设启用了PHP的allow_url_fopen。很可能feed正在进行UA和/或referer过滤,所以你必须更好地伪装成一个普通的浏览器。嗨,感谢您的评论文件,第一个选项是“获取内容”,但即使将“允许url”设置为“真”,此url也不起作用:-您假装是普通浏览器的暗示给了我一些想法,如“用户代理”。。。当然,如果有人知道这个解决方案是非常受欢迎的!!我是一个客户端的家伙-谢谢你,先生!如果我能帮忙,请告诉我:-谢谢你,先生!如果我有什么可以帮忙的,请告诉我:-