php - Tricky rss to read with curl -
does body know hot make feed http://maxhire.net/cp/?ea5e6f361d4364703d044f72 read curl? miss curl conf, i'm new this, js
function url_get_contents ($url) { if (!function_exists('curl_init')){ die('curl 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; }
and calling script below,
echo url_get_contents('http://maxhire.net/cp/?ea5e6f361d4364703d044f72');
does not work feed , works other, http: / / x ml.corriereobjects.it/rss/homepage.xml
this website seems expect cookie named aspxautodetectcookiesupport
, if didn't find it redirect cookie detection page, , stuck in loop:
> 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
so need set cookie: aspxautodetectcookiesupport=1
:
curl_setopt($ch, curlopt_cookie, 'aspxautodetectcookiesupport=1');
that solved first problem, problem came up, if didn't set value user-agent send page:
<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>
so add user-agent value:
curl_setopt($ch, curlopt_useragent, "someuseragent");
full code:
function url_get_contents ($url) { if (!function_exists('curl_init')){ die('curl 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; }
Comments
Post a Comment