php使用curl抓取qq空间的访客信息示例

config.php

代码如下:

<?php
define('APP_DIR', dirname(__FILE__));
define('COOKIE_FILE', APP_DIR . '/app.cookie.txt'); //会话记录文件
define('VISITOR_CAPTURE_INTERVAL', 3); //QQ采集间隔
define('VISITOR_DATA_UPLOAD_INTERVAL', '');
define('THIS_TIME', time());

define('REQUEST_TIMEOUT', 20); //请求超时20秒
define('END_LINE', "\n");
define('DEBUG', true); //开启调试

$login_users = array(
    array('user' => '2064556526', 'password' => '909124951'),
    array('user' => '483258700', 'password' => '909124951'),
    array('user' => '1990270522', 'password' => '909124951'),
    array('user' => '2718711637', 'password' => '909124951'),
    array('user' => '2841076562', 'password' => '909124951'),
);

qy.visitor.php

代码如下:

<?php
include('./config.php');
include(APP_DIR . '/qy.visitor.php');

$sessions = array();
$user = $login_users[array_rand($login_users)];

$visitor_capture = new QQVisitorCapture($user['user'], $user['password'], COOKIE_FILE, REQUEST_TIMEOUT, DEBUG, END_LINE);

$visitors = $visitor_capture->getVisitorInfo();

if (empty($visitors)) {
    $this->clearCookies(true);
} else {
    $cckf_service = new CCKFService(SECURITY_KEY,SERVICE_ID,SERVICE_ADDRESS,'', REQUEST_TIMEOUT, DEBUG, END_LINE);
}

qy.class.php

代码如下:

<?php

class Trace
{
    public static function nl($num = 1)
    {
        $str = '';
        for ($i = 0; $i < $num; $i++) {
            $str .= "\n";
        }
        return $str;
    }

public static function br($num = 1)
    {
        $str = '';
        for ($i = 0; $i < $num; $i++) {
            $str .= "<br/>";
        }
        return $str;
    }

public static function write($content, $end_line, $title = null)
    {
        $close = '^^^^^^^^^^^^^^^^^';

if ($title) {
            $start = '--------' . $title . '---------';
        } else {
            $start = '-----------------';
        }

echo $start . $end_line;

if (is_array($content)) {
            print_r($content);
            echo $end_line;
        } else {
            echo $content;
            echo $end_line;
        }

if (empty($content)) {
            echo $end_line;
        } else {
            echo $close . $end_line;
        }
    }

}

class Utils
{

public static function getMicroTime()
    {
        list($mic, $time) = explode(" ", microtime());
        return intval($time) + floatval(sprintf('%.3f', $mic));
    }

public static function getUTCMilliseconds()
    {
        return round(rand(1, 9) / 10 * 2147483647) * round(1, 999) % 10000000000;
    }

public static function decodeURIComponent($content)
    {
        return urldecode(preg_replace("/\\\\x([0-9a-z]{2,3})/i", "%$1", $content));
    }

public static function  jsRandom()
    {
        list($mic, $time) = explode(" ", microtime());
        return $mic;
    }

function loginJsTime()
    {
        list($mic, $time) = explode(" ", microtime());
        return $time . sprintf('%3d', $mic * 1000);

}

protected static function utf8_unicode($c)
    {
        switch (strlen($c)) {
            case 1:
                return ord($c);
            case 2:
                $n = (ord($c[0]) & 0x3f) << 6;
                $n += ord($c[1]) & 0x3f;
                return $n;
            case 3:
                $n = (ord($c[0]) & 0x1f) << 12;
                $n += (ord($c[1]) & 0x3f) << 6;
                $n += ord($c[2]) & 0x3f;
                return $n;
            case 4:
                $n = (ord($c[0]) & 0x0f) << 18;
                $n += (ord($c[1]) & 0x3f) << 12;
                $n += (ord($c[2]) & 0x3f) << 6;
                $n += ord($c[3]) & 0x3f;
                return $n;
        }
    }

public static function  getGTK($str)
    {
        $hash = 5381;
        for ($i = 0, $len = strlen($str); $i < $len; ++$i) {
            $hash += ($hash << 5) + self::utf8_unicode($str[$i]);
        }
        return $hash & 2147483647;
    }

protected static function hexchar2bin($str)
    {
        $arr = '';
        $temp = null;
        for ($i = 0; $i < strlen($str); $i = $i + 2) {
            $arr .= "\\x" . substr($str, $i, 2);
        }
        eval('$temp="' . $arr . '";');
        return $temp;
    }

protected static function getUid($uid)
    {
        $temp = null;
        eval('$temp="' . $uid . '";');
        return $temp;
    }

public static function getEncryption($password, $uin, $vcode)
    {
        $uin = self::getUid($uin);
        $str1 = self::hexchar2bin(strtoupper(md5($password)));
        $str2 = strtoupper(md5($str1 . $uin));
        return strtoupper(md5($str2 . strtoupper($vcode)));
    }

}

class CookieFileExtract
{
    protected $cookie_file;
    protected $cookie_list;

protected function  __construct($cookie_file)
    {
        $this->cookie_file = $cookie_file;

$this->cookie_list = $this->extractFile();
    }

protected function isValidateCookieFile()
    {
        if ($this->cookie_file && file_exists($this->cookie_file)) {
            return true;
        } else {
            return false;
        }
    }

protected function extractFile()
    {
        $cookie_list = array();

if ($this->isValidateCookieFile($this->cookie_file)) {
            $content = file($this->cookie_file);
            if (is_array($content)) {
                foreach ($content as $line) {
                    $line = trim($line);
                    if (strlen($line) > 0 && $line[0] != '#') {
                        $cookie = (preg_split("/\s+/", $line));
                        if (count($cookie) == 7) {
                            $cookie_list[$cookie[5]] = $cookie[6];
                        } else {
                            $cookie_list[$cookie[5]] = '';
                        }
                    }
                }
            }
        }

return $cookie_list;
    }

protected function buildCookieStr($cookies)
    {
        $arr = array();

if (is_array($cookies)) {
            foreach ($cookies as $k => $cookie) {
                $line = $cookie['domain'] . "\t" . "TRUE" . "\t" . $cookie['path'] . "\t" . "FALSE" . "\t" . $cookie['expires'] . "\t" . $k . "\t" . $cookie['value'];
                $arr[] = $line;
            }
        }
        return $arr;
    }

protected function __setCookies($cookies)
    {
        $new_line = array();
        if (is_array($cookies)) {
            if ($this->isValidateCookieFile($this->cookie_file)) {
                $content = file($this->cookie_file);
                if (is_array($content)) {
                    foreach ($content as $line) {
                        $line = trim($line);
                        if (strlen($line) > 0 && $line[0] != '#') {
                            $cookie = (preg_split("/\s+/", $line));
                            if (!in_array($cookie[5], $cookies)) {
                                $new_line[] = $line;
                            }
                        } else {
                            $new_line[] = $line;
                        }
                    }
                }
            }

file_put_contents($this->cookie_file, implode("\n", array_merge($new_line, $this->buildCookieStr($cookies))));
        }
    }

protected function __getAllCookies($refresh = false)
    {
        if ($refresh) {
            $this->cookie_list = $this->extractFile();
        }
        return $this->cookie_list;
    }

protected function __getCookie($cookie_name, $refresh = false)
    {
        $cookie_list = $this->__getAllCookies($refresh);

if (is_array($cookie_list) && array_key_exists($cookie_name, $cookie_list)) {
            return $cookie_list[$cookie_name];
        } else {
            return null;
        }
    }

protected function __clearAllCookies()
    {
        $this->cookie_list = null;
        @unlink($this->cookie_file);
    }
}

class BaseRequest extends CookieFileExtract
{

protected $curl_instance;
    protected $request_timeout;
    protected $debug;
    protected $end_line;
    protected $user_agent = 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:26.0) Gecko/20100101 Firefox/26.0';

protected function __construct($cookie_file, $request_timeout, $debug, $end_line)
    {
        parent::__construct($cookie_file);
        $this->request_timeout = $request_timeout;
        $this->debug = $debug;
        $this->end_line = $end_line;
        $this->initInstance();
    }

protected function initInstance()
    {

$this->curl_instance = curl_init();

if ($this->isValidateCookieFile()) {
            curl_setopt($this->curl_instance, CURLOPT_COOKIEJAR, $this->cookie_file);
            curl_setopt($this->curl_instance, CURLOPT_COOKIEFILE, $this->cookie_file);
        }

curl_setopt($this->curl_instance, CURLOPT_TIMEOUT, $this->request_timeout);
        curl_setopt($this->curl_instance, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($this->curl_instance, CURLOPT_HEADER, 1);
        curl_setopt($this->curl_instance, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($this->curl_instance, CURLOPT_SSL_VERIFYHOST, 0);
        curl_exec($this->curl_instance);

}

function setCookies($cookies)
    {
        $this->closeInstance();
        $this->__setCookies($cookies);
        $this->initInstance();
    }

protected function getAllCookies($refresh = false)
    {
        $this->closeInstance();
        $cookies = $this->__getAllCookies($refresh);
        $this->initInstance();
        return $cookies;
    }

protected function clearAllCookies($refresh = false)
    {
        $this->closeInstance();
        $this->__clearAllCookies();

if ($refresh) {
            $this->initInstance();
        }
    }

protected function getCookie($name, $refresh = false)
    {
        $this->closeInstance();
        $cookie = $this->__getCookie($name, $refresh);
        $this->initInstance();
        return $cookie;
    }

protected function getRequestInstance()
    {
        return $this->curl_instance;
    }

protected function closeInstance()
    {
        if (is_resource($this->curl_instance)) {
            curl_close($this->curl_instance);
        }
    }

protected function resetInstance()
    {
        $this->closeInstance();
        @unlink($this->cookie_file);
        $this->initInstance();
    }

protected function requestExec($option)
    {

curl_setopt_array($this->getRequestInstance(), $option);

//if ($this->debug) {
        //    $result = curl_exec($this->getRequestInstance());
        //    Trace::write($result, $this->end_line, 'request output');
        //} else {
        return curl_exec($this->getRequestInstance());
        //}
    }
}

class QQVisitorRequest extends BaseRequest
{
    protected $user;
    protected $password;

protected function __construct($user, $password, $cookie_file, $request_timeout, $debug, $end_line)
    {

parent::__construct(dirname($cookie_file) . '/' . $user . '.' . basename($cookie_file), $request_timeout, $debug, $end_line);
        $this->user = $user;
        $this->password = $password;
    }
}

class ResultExtract
{

public static function  getCoreJsInfo($content, $user)
    {
        $arr = array();
        preg_match('/cfg\s*=\s*\{(.*?)\s*\}\s*,\s*URL_PARAM_HASH/s', $content, $m);
        if (count($m) > 0) {
            $f = preg_replace('/\s*/', '', $m[1]);
            $f = preg_replace('/"\+g\_iLoginUin\+"/', $user, $f);
            $f = preg_replace('/\$j\.cookie.get\("hotfeeds_closed"\)==1\?""\:/', '', $f);

$f = explode(",", $f);
            if (count($f) > 0) {
                foreach ($f as $t) {
                    $t = trim($t);
                    $p = strpos($t, ':');
                    $key = trim(substr($t, 0, $p), '"');
                    $value = trim(substr($t, $p + 1), '"');
                    if ($key) {
                        $arr[$key] = $value;
                    }
                }

if (count($arr) > 0) {
                    $arr['visitor'] = $arr;
                }
            }
        }

return $arr;
    }

public static function  enterQzoneSuccess($content)
    {
        $arr = array();
        $arr2 = array();
        preg_match('/g_Data\s*=\s*{\s*feedsPart1\s*:\s*(.*?)\s*,\s*feedsPart2/s', $content, $m);

if (count($m) > 0) {
            $f = preg_replace('/\s*/', '', $m[1]);
            $f = preg_replace('/([\{,])([^,]*?)(\:)/', '$1"$2"$3', $f);
            $f = preg_replace('/:\'(.*?)\'([,\}])/', ':"$1"$2', $f);
            $arr = json_decode($f, true);
            $arr = $arr['main'];
        }

preg_match('/g_type.*?g_IZone_Flag/s', $content, $m);

if (count($m) > 0) {
            $f = preg_replace('/\s*/', '', $m[0]);
            $f = explode(",", $f);

foreach ($f as $t) {
                $t = trim($t);
                $p = strpos($t, '=');
                $key = trim(substr($t, 0, $p));
                $value = trim(substr($t, $p + 1), '"');
                if ($key) {
                    $arr2[$key] = $value;
                }
            }
        }

return array_merge($arr, $arr2);

}

public static function getLoginJsInfo($content)
    {

$s = preg_replace('/.*?pt\.plogin\s*=\s*\{(.*?)aqScanLink.*/s', '$1', $content);
        preg_match('/.*js_type\s*:\s*(\d+)\s*,.*/', $s, $m);

if (count($m) > 1) {
            return array('js_type' => $m[1]);
        }

return array();
    }

public static function getLoginAddress($content)
    {
        preg_match('/.*?<\s*iframe\s*id\s*=\s*"login_frame"\s*name\s*=\s*"login_frame".*?src\s*=\s*"(.*?xui\.ptlogin2\.qq\.com.*?)".*?>\s*<\/iframe>.*?/', $content, $m);

if (count($m) > 1) {
            return html_entity_decode($m[1]);
        }
        return null;
    }

public static function checkLoginSuccess($content)
    {

preg_match_all('/.*?\((.*)\).*?/', $content, $match);
        if ($match[1][0]) {
            $g = explode(',', $match[1][0]);
            if (count($g) > 1) {
                if (($g[count($g) - 2]) == "'登录成功!'") {
                    $url_parts = parse_url($g[2]);
                    parse_str($url_parts['query'], $arr);
                    if (array_key_exists('ptsig', $arr)) {
                        $ptsig = $arr['ptsig'];
                    } else {
                        $ptsig = null;
                    }
                    return array('status' => true, 'value' => array('url' => $g[2], 'ptsig' => $ptsig));
                }
            }
        }
        return array('status' => false);
    }

public static function rightFrameVisitors($content)
    {
        $visitor_list = array();
        $f = preg_replace('/\s*/', '', $content);
        $f = preg_replace('/.*?_Callback\((\{.*?\})\).*?/', '$1', $f);
        $f = json_decode($f, true);

if (is_array($f) && count($f) > 0 && array_key_exists('data', $f)
            && array_key_exists('module_3', $f['data'])
            && array_key_exists('data', $f['data']['module_3'])
            && array_key_exists('items', $f['data']['module_3']['data'])
        ) {

$visitors = $f['data']['module_3']['data']['items'];

foreach ($visitors as $visitor) {

if (!array_key_exists('loc', $visitor)) {
                    $visitor_list [] = array(
                        'uin' => $visitor['uin'], 'name' => $visitor['name'], 'online' => $visitor['online'], 'time' => $visitor['time'],
                        'img' => $visitor['img'], 'yellow' => $visitor['yellow'], 'supervip' => $visitor['supervip'],
                    );
                }
            }
        }

return $visitor_list;
    }

public static function getVisitors($content)
    {

$f = preg_replace('/\s*/', '', $content);
        preg_match('/^.*?(\{.*?\})\);\s*$/', $f, $m);

$visitor_list = array();

if (is_array($m) && count($m) > 1 && strlen($m[1]) > 0) {
            $visitors = json_decode(trim($m[1]), true);

if (array_key_exists('data', $visitors) && array_key_exists('items', $visitors['data'])) {

foreach ($visitors['data']['items'] as $visitor) {

if ($visitor['name']) {
                        $_ = array(
                            'uin' => $visitor['uin'], 'name' => $visitor['name'], 'time' => $visitor['time'],
                            'yellow' => $visitor['yellow'], 'supervip' => $visitor['supervip'],
                        );
                        if (array_key_exists('portraitlabel', $visitor)) {
                            $_['portraitlabel'] = $visitor['portraitlabel'];
                        }
                        $visitor_list[] = $_;

if (array_key_exists('uins', $visitor)) {
                            foreach ($visitor['uins'] as $uins) {
                                $_ = array(
                                    'uin' => $uins['uin'], 'name' => $uins['name'], 'time' => $uins['time'],
                                    'yellow' => $uins['yellow'], 'supervip' => $uins['supervip'],
                                );

if (array_key_exists('portraitlabel', $uins)) {
                                    $_['portraitlabel'] = $uins['portraitlabel'];
                                }
                                $visitor_list[] = $_;
                            }
                        }
                    }
                }
            }
        }
        return $visitor_list;
    }

public static function  checkVC($content)
    {
        preg_match_all('/.*?\((.*)\).*?/', $content, $match);

if (strlen($match[1][0]) > 1) {
            $m = str_replace("'", '', $match[1][0]);
            $g = explode(',', $m);

if (count($g) == 3) {
                return array('saltUin' => $g[2], 'verifycode' => $g[1], 'RSAKey' => $g[2] ? false : true);
            }
        }
        return array();
    }

public static function getLoginInfo($content)
    {
        $s = preg_replace('/.*?pt\.ptui\s*=\s*\{(.*?)\}\s*;.*/s', '$1', $content);
        $e = preg_split('/,\s*/', trim($s));

$info = array();

foreach ($e as $t) {

$t = trim($t);
            $p = strpos($t, ':');
            $key = trim(substr($t, 0, $p));
            $value = trim(substr($t, $p + 1));

if (preg_match('/encodeURIComponent/', $value)) {
                $value = preg_replace('/^encodeURIComponent\s*\(\s*"(.*)?"\s*\)\s*,?$/', '$1', $value);
            } else {
                $value = trim($value, '",');
            }

if ($key) {
                $info[$key] = urldecode($value);
            }
        }
        return $info;
    }

}

class QQVisitorCapture extends QQVisitorRequest
{

public function __construct($user, $password, $cookie_file, $request_timeout, $debug, $end_line)
    {
        parent:: __construct($user, $password, $cookie_file, $request_timeout, $debug, $end_line);
    }

public function trace($content, $title)
    {
        if ($this->debug = true) {
            Trace:: write($content, $this->end_line, $title);
        }
    }

public function error($message)
    {
        $this->trace($message, 'login error ');
        return false;
    }

public function success()
    {
        return true;
    }

public function getGTKEncryption()
    {
        return Utils ::getGTK($this->getCookie('skey', true));
    }

public function getCookies($refresh = false)
    {
        return $this->getAllCookies($refresh);
    }

public function clearCookies($refresh = false)
    {
        return $this->clearAllCookies($refresh);
    }

public function login()
    {
        $login_submit_info_url = null;
        $login_submit_info_url = $this->visitQzone();

$this->setCookies(array(
            'pgv_pvid' => array(
                'value' => Utils::getUTCMilliseconds(), 'path' => '/', 'domain' => '.qq.com', 'expires' => '0'
            ),
            'pgv_info' => array(
                'value' => 'ssid=s' . Utils::getUTCMilliseconds(), 'path' => '/', 'domain' => '.qq.com', 'expires' => '0'
            ),
            '_qz_referrer' => array(
                'value' => 'qzone.qq.com', 'path' => '/', 'domain' => '.qq.com', 'expires' => '0'
            ),
        ));

//log
        $this->trace('', 'login begin');

//log
        $this->trace($login_submit_info_url, '$login_submit_info_url===');

$login_submit_info = $this->getLoginSubmitInfo($login_submit_info_url);

//log
        $this->trace($login_submit_info, '$login_submit_info===');

if (empty($login_submit_info)) {
            $this->error('err-001');
        }

$this->report();

//log
        $this->trace('', 'getLoginJs');
        $js_arr = $this->getLoginJs();

//log
        $this->trace($js_arr, '$getLoginJs===');

if (empty($js_arr)) {
            $this->error('err-002');
        }

$u = $uin = $this->user;
        $r = Utils::jsRandom();
        $verifycode = null;
        $pt_rsa = null;
        $ptredirect = $login_submit_info['target'];
        $h = $t = $g = $from_ui = 1;
        $p = null;
        $regmaster = $login_submit_info['regmaster'];
        $u1 = Utils::decodeURIComponent($login_submit_info['s_url']);
        $ptlang = $login_submit_info['lang'];
        $action = strval(rand(5, 9)) . '-' . strval(strlen($this->user) + strlen($this->password) + rand(1, 5)) . '-' . Utils::loginJsTime();
        $js_ver = $login_submit_info['ptui_version'];
        $js_type = $js_arr['js_type'];
        $login_sig = $login_submit_info['login_sig'];
        $appid = $aid = $login_submit_info['appid'];
        $pt_qzone_sig = $login_submit_info['pt_qzone_sig'];
        $daid = $login_submit_info['daid'];

//log
        $this->trace('', 'checkVC');
        $check_data = $this->checkVC($regmaster, $appid, $js_ver, $js_type, $login_sig, $u1, $r);

if (count($check_data) !== 3) {
            $this->error('err-003');
        }

//log
        $this->trace($check_data, '$check_data===');

//log
        $this->trace(json_encode($check_data), '$check_data===');

$verifycode = $check_data['verifycode'];

if ($check_data['RSAKey']) {
            $this->error('err-004');
        } else {
            $p = Utils::getEncryption($this->password, $check_data['saltUin'], $verifycode);
            $pt_rsa = 0;
        }

//log
        $this->trace('', 'submitLogin');

$this->setCookies(array(
            'ptui_loginuin' => array(
                'value' => $this->user, 'path' => '/', 'domain' => '.qq.com', 'expires' => '0'
            ),
        ));

$login_result = $this->submitLogin($verifycode, $p,
            $pt_rsa, $ptredirect, $u1,
            $h, $t, $g, $from_ui,
            $ptlang, $action, $js_ver, $js_type,
            $login_sig, $aid, $daid, $pt_qzone_sig);

if ($login_result['status']) {
            $this->trace('登录成功', 'submitLogin');
            $this->trace($login_result, '$login_result====');
            $this->loginSuccessRedirect($login_result['value']['url']);
            $this->setCookies(array(
                'fnc' => array(
                    'value' => 1, 'path' => '/', 'domain' => '.qzone.qq.com', 'expires' => '0'
                ),
            ));
            $enterQzoneInfo = $this->enterQzone($login_result['value']['url'], $login_result['value']['ptsig']);

//log
            $this->trace($enterQzoneInfo, '$enterQzoneInfo===');

if ($enterQzoneInfo) {

$this->trace('进入空间', 'enterQzone');

//$referer = $login_result['value']['url'];
                //$scope = 0;

//log
                $this->trace('', 'getCoreJs');
                $coreJsInfo = $this->getCoreJs();
                $this->trace($coreJsInfo, 'getCoreJs===');

$this->setCookies(array(
                    'qzone_referer' => array(
                        'value' => $login_result['value']['url'], 'path' => '/', 'domain' => '.local.cckf123456789.com', 'expires' => '0'
                    ),
                    'qzone_visitor_param' => array(
                        'value' => implode('|', array_values($coreJsInfo['visitor'])), 'path' => '/', 'domain' => '.local.cckf123456789.com', 'expires' => '0'
                    ),
                ));

//log
                //$this->trace('', 'rightFrameVisitor');
                //print_r($this->rightFrameVisitor($referer, implode('|', array_values($coreJsInfo['visitor']))));

return $this->success();
            } else {
                $this->error('err-006');
            }

} else {
            $this->error('err-005');
        }
    }

protected function visitQzone()
    {
        $options = array(
            CURLOPT_TIMEOUT => $this->request_timeout,
            CURLOPT_HEADER => 1,
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_URL => 'http://qzone.qq.com',
            CURLOPT_HTTPHEADER => array(
                'Referer:http://xui.ptlogin2.qq.com/cgi-bin/xlogin?proxy_url=http%3A//qzs.qq.com/qzone/v6/portal/proxy.html&daid=5&pt_qzone_sig=1&hide_title_bar=1&low_login=0&qlogin_auto_login=1&no_verifyimg=1&link_target=blank&appid=549000912&style=22&target=self&s_url=http%3A//qzs.qq.com/qzone/v5/loginsucc.html?para=izone&pt_qr_app=%E6%89%8B%E6%9C%BAQQ%E7%A9%BA%E9%97%B4&pt_qr_link=http%3A//z.qzone.com/download.html&self_regurl=http%3A//qzs.qq.com/qzone/v6/reg/index.html&pt_qr_help_link=http%3A//z.qzone.com/download.html',
                'User-Agent:' . $this->user_agent,
                'Host:qzone.qq.com',
                'Accept-Language:zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3',
                'Connection:keep-alive',)
        );

return ResultExtract::getLoginAddress($this->requestExec($options));
    }

protected function getLoginJs()
    {
        $options = array(
            CURLOPT_TIMEOUT => $this->request_timeout,
            CURLOPT_HEADER => 1,
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_URL => 'http://imgcache.qq.com/ptlogin/ver/10067/js/c_login_old.js',
            CURLOPT_HTTPHEADER => array(
                'Referer:http://xui.ptlogin2.qq.com/cgi-bin/xlogin?proxy_url=http%3A//qzs.qq.com/qzone/v6/portal/proxy.html&daid=5&pt_qzone_sig=1&hide_title_bar=1&low_login=0&qlogin_auto_login=1&no_verifyimg=1&link_target=blank&appid=549000912&style=22&target=self&s_url=http%3A//qzs.qq.com/qzone/v5/loginsucc.html?para=izone&pt_qr_app=%E6%89%8B%E6%9C%BAQQ%E7%A9%BA%E9%97%B4&pt_qr_link=http%3A//z.qzone.com/download.html&self_regurl=http%3A//qzs.qq.com/qzone/v6/reg/index.html&pt_qr_help_link=http%3A//z.qzone.com/download.html',
                'User-Agent:' . $this->user_agent,
                'Host:imgcache.qq.com',
                'Connection:keep-alive',)
        );

return ResultExtract::getLoginJsInfo($this->requestExec($options));
    }

public function checkVC($regmaster, $appid, $js_ver, $js_type, $login_sig, $u1, $r)
    {

$options = array(
            CURLOPT_TIMEOUT => $this->request_timeout,
            CURLOPT_HEADER => 1,
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_URL => 'http://check.ptlogin2.qq.com/check?' . http_build_query(array(
                'regmaster' => $regmaster,
                'uin' => $this->user,
                'appid' => $appid,
                'js_ver' => $js_ver,
                'js_type' => $js_type,
                'login_sig' => $login_sig,
                'u1' => $u1,
                'r' => $r,
            )),
            CURLOPT_HTTPHEADER => array(
                'Referer:http://xui.ptlogin2.qq.com/cgi-bin/xlogin?proxy_url=http%3A//qzs.qq.com/qzone/v6/portal/proxy.html&daid=5&pt_qzone_sig=1&hide_title_bar=1&low_login=0&qlogin_auto_login=1&no_verifyimg=1&link_target=blank&appid=549000912&style=22&target=self&s_url=http%3A//qzs.qq.com/qzone/v5/loginsucc.html?para=izone&pt_qr_app=%E6%89%8B%E6%9C%BAQQ%E7%A9%BA%E9%97%B4&pt_qr_link=http%3A//z.qzone.com/download.html&self_regurl=http%3A//qzs.qq.com/qzone/v6/reg/index.html&pt_qr_help_link=http%3A//z.qzone.com/download.html',
                'User-Agent:' . $this->user_agent,
                'Host:check.ptlogin2.qq.com',
                'Accept-Language:zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3',
                'Connection:keep-alive',
            )
        );

return ResultExtract::checkVC($this->requestExec($options));
    }

protected function report()
    {
        $url = 'http://ui.ptlogin2.qq.com/cgi-bin/report?id=358342&t=' . Utils::jsRandom();

$options = array(
            CURLOPT_TIMEOUT => $this->request_timeout,
            CURLOPT_HEADER => 1,
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_URL => $url,
            CURLOPT_HTTPHEADER => array(
                'Referer:http://xui.ptlogin2.qq.com/cgi-bin/xlogin?proxy_url=http%3A//qzs.qq.com/qzone/v6/portal/proxy.html&daid=5&pt_qzone_sig=1&hide_title_bar=1&low_login=0&qlogin_auto_login=1&no_verifyimg=1&link_target=blank&appid=549000912&style=22&target=self&s_url=http%3A//qzs.qq.com/qzone/v5/loginsucc.html?para=izone&pt_qr_app=%E6%89%8B%E6%9C%BAQQ%E7%A9%BA%E9%97%B4&pt_qr_link=http%3A//z.qzone.com/download.html&self_regurl=http%3A//qzs.qq.com/qzone/v6/reg/index.html&pt_qr_help_link=http%3A//z.qzone.com/download.html',
                'User-Agent:' . $this->user_agent,
                'Host:ui.ptlogin2.qq.com',
                'Connection:keep-alive',)
        );

$this->requestExec($options);

}

protected function getLoginSubmitInfo($url)
    {
        $options = array(
            CURLOPT_TIMEOUT => $this->request_timeout,
            CURLOPT_HEADER => 1,
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_URL => $url,
            CURLOPT_HTTPHEADER => array(
                'Referer:http://qzone.qq.com/',
                'User-Agent:' . $this->user_agent,
                'Host:xui.ptlogin2.qq.com',
                'Connection:keep-alive',
            )
        );

return ResultExtract::getLoginInfo($this->requestExec($options));
    }

protected function submitLogin($verifycode, $p,
                                   $pt_rsa, $ptredirect, $u1,
                                   $h, $t, $g, $from_ui,
                                   $ptlang, $action, $js_ver, $js_type,
                                   $login_sig, $aid, $daid, $pt_qzone_sig)
    {
        $url = 'http://ptlogin2.qq.com/login';

$url .= '?' . http_build_query(array(
                'u' => $this->user,
                'verifycode' => $verifycode));

$url .= '&p=' . $p; ###

$url .= '&' . http_build_query(array(
                'pt_rsa' => $pt_rsa,
                'ptredirect' => $ptredirect,
                'u1' => $u1,
                'h' => $h,
                't' => $t,
                'g' => $g,
                'from_ui' => $from_ui,
                'ptlang' => $ptlang,
                'action' => $action,
                'js_ver' => $js_ver,
                'js_type' => $js_type,
            ));

$url .= '&login_sig=' . $login_sig; ###

$url .= '&' . http_build_query(array(
                'aid' => $aid,
                'daid' => $daid,
                'pt_qzone_sig' => $pt_qzone_sig));

$options = array(
            CURLOPT_TIMEOUT => $this->request_timeout,
            CURLOPT_HEADER => 1,
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_URL => $url,
            CURLOPT_HTTPHEADER => array(
                'Referer:http://xui.ptlogin2.qq.com/cgi-bin/xlogin?proxy_url=http%3A//qzs.qq.com/qzone/v6/portal/proxy.html&daid=5&pt_qzone_sig=1&hide_title_bar=1&low_login=0&qlogin_auto_login=1&no_verifyimg=1&link_target=blank&appid=549000912&style=22&target=self&s_url=http%3A//qzs.qq.com/qzone/v5/loginsucc.html?para=izone&pt_qr_app=%E6%89%8B%E6%9C%BAQQ%E7%A9%BA%E9%97%B4&pt_qr_link=http%3A//z.qzone.com/download.html&self_regurl=http%3A//qzs.qq.com/qzone/v6/reg/index.html&pt_qr_help_link=http%3A//z.qzone.com/download.html',
                'User-Agent:' . $this->user_agent,
                'Host:ptlogin2.qq.com',
                'Accept-Language:zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3',
                'Connection:keep-alive',
            )
        );

return ResultExtract::checkLoginSuccess($this->requestExec($options));
    }

public function loginSuccessRedirect($url)
    {
        $options = array(
            CURLOPT_TIMEOUT => $this->request_timeout,
            CURLOPT_HEADER => 1,
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_URL => $url,

CURLOPT_HTTPHEADER => array(
                'Referer:http://xui.ptlogin2.qq.com/cgi-bin/xlogin?proxy_url=http%3A//qzs.qq.com/qzone/v6/portal/proxy.html&daid=5&pt_qzone_sig=1&hide_title_bar=1&low_login=0&qlogin_auto_login=1&no_verifyimg=1&link_target=blank&appid=549000912&style=22&target=self&s_url=http%3A//qzs.qq.com/qzone/v5/loginsucc.html?para=izone&pt_qr_app=%E6%89%8B%E6%9C%BAQQ%E7%A9%BA%E9%97%B4&pt_qr_link=http%3A//z.qzone.com/download.html&self_regurl=http%3A//qzs.qq.com/qzone/v6/reg/index.html&pt_qr_help_link=http%3A//z.qzone.com/download.html',
                'User-Agent:' . $this->user_agent,
                'Host:qzs.qq.com',
                'Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
                'Connection:keep-alive',
                'DNT:1',
            )
        );
        $this->requestExec($options);
    }

public function  enterQzone($referer, $ptsig)
    {
        $options = array(
            CURLOPT_TIMEOUT => $this->request_timeout,
            CURLOPT_HEADER => 1,
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_URL => 'http://user.qzone.qq.com/' . $this->user . '?ptsig=' . $ptsig,

CURLOPT_HTTPHEADER => array(
                'Referer:' . $referer,
                'Host:user.qzone.qq.com',
                'Connection:keep-alive',
            )
        );

return ResultExtract::enterQzoneSuccess($this->requestExec($options));
    }

public function getCoreJs()
    {
        $options = array(
            CURLOPT_TIMEOUT => $this->request_timeout,
            CURLOPT_HEADER => 1,
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_URL => "http://ctc.qzonestyle.gtimg.cn/c/=/qzone/v8/engine/cpu.js,/qzone/v8/ic/qm.js,/qzone/v8/ic/tab_menu.js,/qzone/v8/ic/feeds.js,/qzone/v8/ic/tab_friend_feed.js,/qzone/v8/toolbar/core.js",
        );

return ResultExtract::getCoreJsInfo($this->requestExec($options), $this->user);
    }

public function getVisitorInfo($mask = 7, $page = 1, $fupdate = 1, $clear = 1)
    {
        $options = array(
            CURLOPT_TIMEOUT => $this->request_timeout,
            CURLOPT_HEADER => 1,
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_URL => 'http://g.qzone.qq.com/cgi-bin/friendshow/cgi_get_visitor_more?' . http_build_query(array(
                'uin' => $this->user,
                'mask' => $mask,
                'g_tk' => $this->getGTKEncryption(),
                'page' => $page,
                'fupdate' => $fupdate,
                'clear' => $clear,
                'sd' => Utils::jsRandom(),
            )),

CURLOPT_HTTPHEADER => array(
                'Referer:http://ctc.qzs.qq.com/qzone/v6/friend_manage/visitors.html',
                'User-Agent:' . $this->user_agent,
                'Host:g.qzone.qq.com',
                'Connection:keep-alive',
            )
        );

return ResultExtract::getVisitors($this->requestExec($options));
    }

public function  rightFrameVisitor()
    {
        $param = Utils ::getGTK($this->getCookie('qzone_visitor_param', true));
        $referver = Utils ::getGTK($this->getCookie('qzone_referer'));

$options = array(
            CURLOPT_TIMEOUT => $this->request_timeout,
            CURLOPT_HEADER => 1,
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_URL => 'http://r.qzone.qq.com/cgi-bin/right_frame.cgi?' . http_build_query(array(
                'uin' => $this->user,
                'param' => $param,
                'g_tk' => $this->getGTKEncryption(),
            )),

CURLOPT_HTTPHEADER => array(
                'Referer:' . $referver,
                'User-Agent:' . $this->user_agent,
                'Host:r.qzone.qq.com',
                'Connection:keep-alive',
            )
        );

return ResultExtract::rightFrameVisitors($this->requestExec($options));
    }

}

class CCKFServiceRequest extends BaseRequest
{
    protected $service_address;
    protected $service_id;
    protected $security_key;

public function __construct($security_key, $service_id, $service_address, $cookie_file, $request_timeout, $debug, $end_line)
    {
        parent:: __construct($cookie_file, $request_timeout, $debug, $end_line);
        $this->service_address = $service_address;
        $this->service_id = $service_id;
        $this->security_key = $security_key;
    }
}

class CCKFService extends BaseRequest
{
    public function __construct($security_key, $service_id, $service_address, $cookie_file, $request_timeout, $debug, $end_line)
    {
        parent:: __construct($security_key, $service_id, $service_address, $cookie_file, $request_timeout, $debug, $end_line);
    }

public function uploadData($data)
    {
        if (is_array($data) && !empty($data)) {
            $options = array(
                CURLOPT_TIMEOUT => $this->request_timeout,
                CURLOPT_HEADER => 1,
                CURLOPT_RETURNTRANSFER => 1,
                CURLOPT_URL => $this->service_address . '?' . http_build_query(array()),
            );
        }
    }
}

class BaseConfigFileUtils
{
    protected $file;

public function __construct($file)
    {
        $this->file = $file;
    }

public function extractFile()
    {
        $f_str = '';

$fp = fopen($this->file, 'r');
        if (flock($fp, LOCK_SH)) {
            while (!feof($fp)) {
                $f_str .= fgets($fp);
            }
            flock($fp, LOCK_UN);
        }
        fclose($fp);
        $c = json_decode($f_str, true);
        return is_array($c) ? $c : array();
    }
}

class RunAtTimeConfig extends BaseConfigFileUtils
{
    protected $visitor_capture_interval;
    protected $config;

public function __construct($file, $visitor_capture_interval)
    {
        parent::__construct($file);
        $this->config = $this->extractFile();
        $this->visitor_capture_interval = $visitor_capture_interval;
    }

public function  updateConfig($arr)
    {
        $this->config = $this->extractFile();
        if ($this->isValidateRun()) {
            $fp = fopen($this->file, 'w');
            if (flock($fp, LOCK_EX)) {
                fwrite($fp, json_encode(array_merge($this->config, $arr)));
                flock($fp, LOCK_UN);
            }
            fclose($fp);
            return true;
        }
        return false;
    }

public function  getConfig($item)
    {
        if (is_array($this->config) && array_key_exists($item, $this->config)) {
            return $this->config[$item];
        }
        return null;
    }

public function isValidateRun()
    {
        $c_time = Utils::getMicroTime();
        $run_at_time = floatval($this->getConfig('run_at_time'));
        if ($c_time - $run_at_time >= $this->visitor_capture_interval) {
            return true;
        } else {
            return false;
        }
    }
}

class VisitorList extends BaseConfigFileUtils
{
    protected $visitor_list;

/**$visitor_list [] = array(
    'uin' => $visitor['uin'], 'name' => $visitor['name'], 'online' => $visitor['online'], 'time' => $visitor['time'],
    'img' => $visitor['img'], 'yellow' => $visitor['yellow'], 'supervip' => $visitor['supervip'],
    );**/

public function __construct($file)
    {
        parent::__construct($file);
        $this->visitor_list = $this->extractFile();
    }

public function updateVisitor($visitor)
    {
        if (is_array($visitor) && !empty($visitor)) {
            foreach ($visitor as $one) {
                array_unshift($this->visitor_list, $one);
            }
        }

$fp = fopen($this->file, 'w');
        if (flock($fp, LOCK_EX)) {
            fwrite($fp, json_encode($this->visitor_list));
            flock($fp, LOCK_UN);
        }
        fclose($fp);
    }

public function addVisitor($visitor)
    {
        $list = array();
        if (is_array($visitor) && !empty($visitor)) {
            foreach ($visitor as $one) {
                if (!$this->isVisitorExist($one['name'])) {
                    $list[] = $one;
                }
            }
            $this->updateVisitor($list);
        }

return $list;
    }

public function isVisitorExist($name)
    {
        foreach ($this->visitor_list as $one) {
            if ($one['name'] == $name) {
                return true;
            }
        }
        return false;
    }
}

(0)

相关推荐

  • thinkphp判断访客为手机端或PC端的方法

    本文实例讲述了thinkphp判断访客为手机端或PC端的方法.分享给大家供大家参考.具体实现方法如下: 一.问题: 近日准备给自己的网站做一个小升级,让用户在手机二维码扫描的时候显示适合手机端来展示的模版[我用的是ThinkPHP3.0],代码是参考别人的 二.实现方法: 这里先说下大概的一个思路 简单两步: 统版本号和浏览器以及它的版本号(贴出的代码中数组中只有移动端信息,因此后面只需判断是否为数组中的某一个值即可). 根据数组中的值来判断访客是否为手机.pad.之类的移动端,如果是的话就规定

  • php 向访客和爬虫显示不同的内容

    听说本方法会触犯搜索引擎的一些操作原则, 有可能被被各搜索引擎处罚, 甚至删除网站. 所以我刚刚已经撤下这样的处理, 直到确定其不属于作弊. 有魄力的朋友可以继续使用, 但后果自负. 本博客的首页和存档页面以列表的形式显示文章, 在访客点击展开文章时才加载文章的内容. 因为文章的内容部分包含了大量的文字和图片, 需要大量的加载时间和流量. 尽快地向访客展示网页可以挽留大量的来访者. 而对于手机用户来说, 加载时间和流量则更为重要. 一般来说, 网站的首页是搜索引擎访问最多的页面, 应该尽可能的向

  • 在WordPress中使用PHP脚本来判断访客来自什么国家

    区分访客国家有什么用? 这里是几个我利用该功能的例子. 1.区分网站功能 这个博客有翻译文章的功能, 这是为了方便海外访客阅读文章, 但对中国人显得十分多余. 所以我通过 IP 判断国家, 对中国大陆地区屏蔽翻译功能. 2.区分展示广告 比如中国大陆地区在侧边栏最下方看到的是拿福能的广告, 而其他地区看到的是 Google 的广告. hostucan 是我的一个广告主, 有英文网站, 也有中文网站, 所以我可以向他提供区分展示服务, 免得浪费流量. 3.屏蔽布点服务 海外有很多好的服务平台, 在

  • php 判断访客是否为搜索引擎蜘蛛的函数代码

    复制代码 代码如下: /** * 判断是否为搜索引擎蜘蛛 * * @author Eddy * @return bool */ function isCrawler() { $agent= strtolower($_SERVER['HTTP_USER_AGENT']); if (!empty($agent)) { $spiderSite= array( "TencentTraveler", "Baiduspider+", "BaiduGame",

  • 利用PHP获取网站访客的所在地位置

    前言 大家应该都有所体会,如果是做大型项目的话,网站获取用户的本地信息就很关键了,比如58分类信息网,在用户访问的时候会自己判断用户所在地的信息,然后可以跳转到相应的分站上面,这样给用户的体验很好,而不是全国各地的用户全部都来访问北京站或者上海站. 利用PHP获取访客所在地位置在大型站点中的应用很广,当然,除了这个应用之外,还可以举一反三出许多好玩的东西,今天就在做一个小项目的时候,用到了,在站点不同地区显示不同内容的小功能,其实跟上面的实例差不多. 实现分析 制作这样的一个小功能,当然首先就要

  • 利用PHP获取访客IP、地区位置、浏览器及来源页面等信息

    前言 本文中主要介绍了关于利用PHP获取访客IP.地区位置.浏览器及来源页面等信息的相关内容,分享出来供大家参考学习,下面来一起看看详细的介绍: 不多说了,每个方法都注释了,可以直接用: 示例代码 <?php //这个类似用来获取访客信息的 //方便统计 class visitorInfo { //获取访客ip public function getIp() { $ip=false; if(!empty($_SERVER["HTTP_CLIENT_IP"])){ $ip = $_

  • php获取指定(访客)IP所有信息(地址、邮政编码、国家、经纬度等)的方法

    本文实例讲述了php获取指定(访客)IP所有信息(地址.邮政编码.国家.经纬度等)的方法.分享给大家供大家参考.具体如下: 调用方法非常简单.这个也需要数据库来支持.数据库中中文和拼音共存才可以. 废话不多说,看代码: <?php function getIpInfo($ip,$timeout=15) { if(!function_exists('curl_init') or !function_exists('simplexml_load_string')) return false; $ch

  • php REMOTE_ADDR之获取访客IP的代码

    <?php $iipp=$_SERVER["REMOTE_ADDR"]; echo $iipp; ?>[/code][code]<?php $user_IP = ($_SERVER["HTTP_VIA"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"] : $_SERVER["REMOTE_ADDR"]; $user_IP = ($user_IP) ? $user_IP : $_SER

  • WordPress中访客登陆实现邮件提醒的PHP脚本实例分享

    登陆邮件提醒实现方法 前提是空间有邮件功能,测试有无邮件功能的方法:登录界面点击"忘记密码",有邮件发到你邮箱就有邮件功能. 一.登录成功提醒 就像银行的登录提醒一样,如果有人登录了系统,就会发一封邮件到邮箱,提醒你有人登录了,如果当时不是你登录,就要引起警惕了.将以下代码放入主题的functions.php中: /***************************************************** 函数名称:wp_login_notify v1.0 by DH.

  • php使用curl抓取qq空间的访客信息示例

    config.php 复制代码 代码如下: <?phpdefine('APP_DIR', dirname(__FILE__));define('COOKIE_FILE', APP_DIR . '/app.cookie.txt'); //会话记录文件define('VISITOR_CAPTURE_INTERVAL', 3); //QQ采集间隔define('VISITOR_DATA_UPLOAD_INTERVAL', '');define('THIS_TIME', time()); define(

  • php curl抓取网页的介绍和推广及使用CURL抓取淘宝页面集成方法

    php的curl可以用来实现抓取网页,分析网页数据用, 简洁易用, 这里介绍其函数等就不详细描述, 放上代码看看: 只保留了其中几个主要的函数. 实现模拟登陆, 其中可能涉及到session捕获, 然后前后页面涉及参数提供形式. libcurl主要功能就是用不同的协议连接和沟通不同的服务器~也就是相当封装了的sock PHP 支持libcurl(允许你用不同的协议连接和沟通不同的服务器)., libcurl当前支持http, https, ftp, gopher, telnet, dict, f

  • vue使用jsonp抓取qq音乐数据的方法

    1.安装jsonp npm install jsonp 2.创建jsonp.js文件,内容如下: import originJSONP from 'jsonp' /** * 封装jsonp * @param {*} url 原始的jsonp第一个参数是url,第二个参数是option,这里为了比较好写参数做了下封装 * @param {obj} data 参数 * @param {*} option jsonp的option */ export default function jsonp (u

  • Python爬取qq空间说说的实例代码

    具体代码如下所示: #coding:utf-8 #!/usr/bin/python3 from selenium import webdriver import time import re import importlib2 import sys importlib2.reload(sys) def startSpider(): driver = webdriver.Chrome('/Users/zachary/zachary/chromedriver.exe') #这个是chormedriv

  • Python实现抓取腾讯视频所有电影的示例代码

    目录 运行环境 实现目的与思路 目的 思路 完整代码 视频缓存ts文件 实现效果 运行环境 IDE丨pycharm 版本丨Python3.6 系统丨Windows 实现目的与思路 目的 实现对腾讯视频目标url的解析与下载,由于第三方vip解析,只提供在线观看,隐藏想实现对目标视频的下载 思路 首先拿到想要看的腾讯电影url,通过第三方vip视频解析网站进行解析,通过抓包,模拟浏览器发送正常请求,通过拿到缓存ts文件,下载视频ts文件,最后通过转换为mp4文件,即可实现正常播放 完整代码 imp

  • PHP curl实现抓取302跳转后页面的示例

    PHP的CURL正常抓取页面程序如下: $url = 'http://www.baidu.com'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_VERBOSE, true); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_NOBODY, true); curl_setopt($ch, CURLO

  • php下通过curl抓取yahoo boss 搜索结果的实现代码

    1.编写curl类,进行网页内容抓取 复制代码 代码如下: class CurlUtil { private $curl; private $timeout = 10; /** * 初始化curl对象 */ public function __construct() { $this->curl = curl_init(); curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($this->curl, CURLO

  • PHP curl 抓取AJAX异步内容示例

    其实抓ajax异步内容的页面和抓普通的页面区别不大.ajax只不过是做了一次异步的http请求,只要使用firebug类似的工具,找到请求的后端服务url和传值的参数,然后对该url传递参数进行抓取即可. 利用Firebug的网络工具 如果抓去的是页面,则内容中没有显示的数据,是一堆JS代码. Code $cookie_file=tempnam('./temp','cookie'); $ch = curl_init(); $url1 = "http://www.cdut.edu.cn/defau

  • 利用curl抓取远程页面内容的示例代码

    最基本的操作如下 复制代码 代码如下: $curlPost = 'a=1&b=2';//模拟POST数据$ch = curl_init();curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:0.0.0.0', 'CLIENT-IP:0.0.0.0'));  //构造IPcurl_setopt($ch, CURLOPT_REFERER, "http://www.jb51.net/");   //构造来路 cur

  • 使用php方法curl抓取AJAX异步内容思路分析及代码分享

    其实抓ajax异步内容的页面和抓普通的页面区别不大.ajax只不过是做了一次异步的http请求,只要使用firebug类似的工具,找到请求的后端服务url和传值的参数,然后对该url传递参数进行抓取即可. 利用Firebug的网络工具 如果抓去的是页面,则内容中没有显示的数据,是一堆JS代码. Code $cookie_file=tempnam('./temp','cookie'); $ch = curl_init(); $url1 = "http://www.cdut.edu.cn/defau

随机推荐