php+phantom.js实现绕过ClourFare或百度云加速验证

下载phantomjs  官网地址http://phantomjs.org/download.html

创建getCookie.js

var page = require('webpage').create()
page.settings.userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.119 Safari/537.36'
page.open('http://www.xxxxxx.com/', function(status) {
    if(status === "success") {
        setInterval(function() {
            var bodytxt = page.evaluate(function() {
                if(document.title != 'Just a moment...') {
                    return true
                }
                return false
            });
            if(bodytxt) {
                for(var i in page.cookies) {
                    console.log(page.cookies[i].name+"="+page.cookies[i].value);
                }
                phantom.exit();
            }
        },1000)
    }
});
page.onError = function(msg, trace) {

};

创建php文件,确保exec函数能运行。

 (30*60)) {
    $cookie = getCookie();
}else{
    $cookie = file_get_contents($dir.'/cookie.txt');
}

$url = 'http://www.xxxxx.com/';
$content = get_url_content($url, $cookie);
echo $content;

function get_url_content($url, $cookie) {
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_HTTPGET, true);
    curl_setopt($ch, CURLOPT_REFERER, $url);
    curl_setopt($ch, CURLOPT_COOKIE, $cookie);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.119 Safari/537.36');
    $content = curl_exec($ch);
    curl_close($ch);
    return $content;
}

 

你可能感兴趣的:(php)