由于CloudFlare,无法从网站获取rss

时间:2014-04-09 08:08:03

标签: php curl rss web-scraping

我试图从http://www.elwatannews.com/home/rssfeeds?sectionId=115获取RSS Feed 这是使用cloudfare.i试图从线程curl: can't fetch rss from website because of CloudFlare中解决问题的网站受到保护我没有得到任何结果。我附上我的代码

<?php
/* cloudflare.php by asifpk  
 * seduce.gravity@gmail.com */
$url = 'http://www.elwatannews.com/home/rssfeeds?sectionId=115';
$data = OpenURLcloudflare($url);
echo htmlspecialchars($data);
//print $data;
//echo htmlspecialchars($data);
//echo htmlspecialchars($data);



function OpenURLcloudflare($url) {
//get cloudflare ChallengeForm
    $page = OpenURL($url);   

    $data = explode('challenge-form',$page);
    $data = explode('=', $data[1]);
    $data = explode(';', $data[1]);
    $value = $data[0];    
    eval("\$jschl_answer=$value;");

    $action = explode('action="',$page);
    $action = explode('"', $action[1]);    
    $action = $action[0];

    $token = explode('"jschl_vc" value="',$page);
    $token = explode('"',$token[1]);
    $token = $token[0];



    //echo "action =".$action;
    $post['act'] = $action;
    $post['jschl_vc'] = $token;

    $post['jschl_answer'] = $jschl_answer;

    $data = OpenURL($url, $post);

    return $data;
}

function OpenURL($url, $post=array()) {   

    $headers[] = 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:13.0) Gecko/20100101 Firefox/13.0.1';
    $headers[] = 'Accept: application/json, text/javascript, */*; q=0.01';
    $headers[] = 'Accept-Language: ar,en;q=0.5';
    $headers[] = 'Connection: keep-alive';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    if(count($post)>0) {
        curl_setopt($ch, CURLOPT_POST, TRUE);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    }
    curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp/curl.cookie');
    curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/curl.cookie');    
    $data = curl_exec($ch);
    return($data);
}
?> 

0 个答案:

没有答案