這篇文章主要介紹了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) { &nb