绕过Incapsula JStest

时间:2014-01-28 18:09:30

标签: php curl web-scraping web-crawler

我正在尝试在使用Incapsula的网站上使用cURL更新我的状态。 由于他们的JS测试安全性,我甚至无法访问主页面。 我正在克隆我的标题,useragent,IP,但我仍然得到错误。

那么有人能想出一个让cURL连接的方法吗?这是我的代码,适用于所有其他网站:

function curl_redirect_exec($ch, &$redirects, $curlopt_header = false) {
    curl_setopt($ch, CURLOPT_HEADER, true);
    //curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Expect:' ) );
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 5.1; rv:7.0.1) Gecko/20100101 Firefox/7.0.1");
    $data = curl_exec($ch);
    $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    if ($http_code == 301 || $http_code == 302) {
        list($header) = explode("\r\n\r\n", $data, 2);
        $matches = array();
        preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches);
        $url = trim(array_pop($matches));
        $url_parsed = parse_url($url);
        if (isset($url_parsed)) {
            curl_setopt($ch, CURLOPT_URL, $url);
            $redirects++;
            return curl_redirect_exec($ch, $redirects);
        }
    }
    if ($curlopt_header)
        return $http_code.$data;
    else {
        list(,$body) = explode("\r\n\r\n", $data, 2);
        return $http_code.$body;
    }
}
function getPage($url,$post=false,$cookijs=false) {
if(!$cookijs) $cookijs = "pass=71c2bce341575e4312fcf19ce2a6eaa9;uid=1174461";
$cookie = tempnam ("/tmp/curlcookies", "CURLCOOKIE");
$timeout = 10;
 $ch = curl_init(); 
 curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
    curl_setopt( $ch, CURLOPT_COOKIEJAR, $cookie );
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_REFERER, 'http://www.enjin.com');
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
    curl_setopt( $ch, CURLOPT_HTTPHEADER, array(
    'Connection: keep-alive',
    'Keep-Alive: 300',
    "Accept-Language: en-US,en;q=0.5",
    "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
));
    curl_setopt( $ch, CURLOPT_MAXREDIRS, 10 );
  #curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Expect:' ) );
  curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; rv:26.0) Gecko/20100101 Firefox/26.0");
curl_setopt($ch, CURLOPT_COOKIE, $cookijs);
 if((isset($post)) && ($post != false)) {
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    }     
 $redirects=5000;
 $data = curl_redirect_exec($ch,$redirects);

 curl_close($ch);
 return $data;
}
$cookijs = array(
"incap_ses_151_48573 " => "eygjTe/9pTa4mxn7Vn0YAkzw51IAAAAAeowsmkMHrBX5eKy0Ejmh8g==",
"visid_incap_48573" => "4E8wP8B5QfKxV6UcDRpmXzHw51IAAAAAQkIPAAAAAACAeLthAV1yLUSyWQXQRO15b5GpU/fLrOMW"
);
$lapa = getPage("http://www.enjin.com", false, $cookijs
);
echo $lapa;

1 个答案:

答案 0 :(得分:1)

我建议你联系enjin并要求他们将你的ip或白名单列入白名单...... 它会节省你的时间,无用的努力和被禁止。