通过空间历史浏览,爬出查看你空间的人(一般限制20人,除非开通黄钻),然后在爬出这20人的浏览记录,依次向下爬,你可以控制爬行深度。
这里仅仅给出怕中代码片段,你可以进一步优化,将QQ分类存储。通过QQ相互浏览关系,可以通过绘图工具绘制好友网络。等等

代码涉及pthreads 如果不清楚请阅读:《PHP 高级编程之多线程》
http://netkiller.github.io/journal/thread.php.html

<?php
/*
Homepage: http://netkiller.github.io
Author: Neo <netkiller@msn.com>
*/
if(!extension_loaded('pthreads')) die ('Please install pthreads'); include_once('Snoopy.class.php'); class CrawlerWorker extends Worker { protected static $dbh;
public function __construct() { }
public function run(){
/*
$dbhost = 'db.example.com'; // 数据库服务器
$dbuser = 'example.com'; // 数据库用户名
$dbpw = 'password'; // 数据库密码
$dbname = 'example'; // 数据库名 self::$dbh = new PDO("mysql:host=$dbhost;port=3306;dbname=$dbname", $dbuser, $dbpw, array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'',
PDO::MYSQL_ATTR_COMPRESS => true,
PDO::ATTR_PERSISTENT => true
)
);
*/
}
protected function getInstance(){
return self::$dbh;
} } /* the collectable class implements machinery for Pool::collect */
class Crawler extends Stackable {
public $depth = 3;
private static $level = 0;
public function __construct($qq) {
$this->qq = $qq;
}
public function run() { try {
$dbh = $this->worker->getInstance();
$this->recursion(array($this->qq));
}
catch(PDOException $e) {
$error = sprintf("%s,%s\n", $mobile, $id );
file_put_contents("mobile_error.log", $error, FILE_APPEND);
}
//printf("runtime: %s, %s\n", date('Y-m-d H:i:s'), $this->worker->getThreadId());
//$lst = $this->qzone($this->qq);
//print_r($lst);
}
public function recursion($qqs){ if( self::$level <= $this->depth){
self::$level++;
}else if(self::$level > 0){
self::$level--;
}
printf("Level: %s\n", self::$level);
//sleep(1);
usleep(mt_rand(10000,1000000));
if(self::$level >= $this->depth){
return;
} foreach($qqs as $uin) {
$lst = $this->qzone($uin);
print_r($lst);
$this->recursion($lst);
}
} public function qzone($qq){
$url = 'http://m.qzone.com/mqz_get_visitor?g_tk=1191852101&res_mode=0&res_uin='.$qq.'&offset=0&count=100&page=1&format=json&t=1401762986882&sid=dODKVcYv6azjN87cxXQ5mao1xgakYjHg18c8aa5e0201%3D%3D';
$snoopy = new Snoopy; // need an proxy?
//$snoopy->proxy_host = "my.proxy.host";
//$snoopy->proxy_port = "8080"; // set browser and referer:
$snoopy->agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
$snoopy->referer = "http://m.qzone.com/"; // set some cookies:
//$snoopy->cookies["SessionID"] = '238472834723489';
//$snoopy->cookies["favoriteColor"] = "blue"; // set an raw-header:
$snoopy->rawheaders["Pragma"] = "no-cache"; // set some internal variables:
$snoopy->maxredirs = 2;
$snoopy->offsiteok = false;
$snoopy->expandlinks = false; // set username and password (optional)
//$snoopy->user = "joe";
//$snoopy->pass = "bloe"; // fetch the text of the website www.google.com:
if($snoopy->fetchtext($url)){
// other methods: fetch, fetchform, fetchlinks, submittext and submitlinks // response code:
//print "response code: ".$snoopy->response_code."<br/>\n"; // print the headers:
//print "<b>Headers:</b><br/>";
//while(list($key,$val) = each($snoopy->headers)){
// print $key.": ".$val."<br/>\n";
//} // print the texts of the website:
//print_r( json_decode($snoopy->results) ); $results = array();
$tmp = json_decode($snoopy->results); if($tmp){
if(property_exists($tmp, 'data')){
foreach( $tmp->data->list as $lst ){
$results[] = $lst->uin;
}
}
}
return ($results); }
else {
print "Snoopy: error while fetching document: ".$snoopy->error."\n";
}
}
} $pool = new Pool(100, \CrawlerWorker::class, []); #foreach (range(1000, 100000) as $number) {
# $pool->submit(new Crawler($number));
#} $pool->submit(new Crawler('13721218'));
$pool->submit(new Crawler('291379'));
//$pool->submit(new Crawler('xxx'));
//$pool->submit(new Crawler('xxx'));
//$pool->submit(new Crawler('xxx'));
// 以此类推
//$pool->submit(new Crawler('nnn')); $pool->shutdown();
?>

***PHP多线程pthreads 实现QQ号码爬虫的更多相关文章

  1. QQ空间爬虫最新分享,一天 400 万条数据(附代码地址)

    http://mp.weixin.qq.com/s?__biz=MzAxMjUyNDQ5OA==&mid=2653552228&idx=1&sn=e476bf23556406c ...

  2. 找女神要QQ号码

    引言 我们组来了个美女程序员,我心里窃喜,哈哈这下机会来了.我在想怎么下手呢?好吧,还是从QQ号码开始,找到女神要到QQ号,哈哈,我真是个天才~~~ 是这样子滴 想法是美好的,现实是残酷的,找女神要Q ...

  3. js正则表达式:验证邮箱格式、密码复杂度、手机号码、QQ号码

    直接上代码             Java   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 ...

  4. 美女程序员是如何将QQ转换成题目中那串数字的--读博文《找女神要QQ号码》

    我只能说好好的端午节你们不约么?,还在这里写代码?我也是够无聊的,下班了不走也在这跟风写着玩!<找女生要QQ号码原文>原文链接http://www.cnblogs.com/iforever ...

  5. JS获得QQ号码的昵称,头像,生日

    这篇文章主要介绍了JS获得QQ号码的昵称,头像,生日的简单实例,有需要的朋友可以参考一下 http://r.qzone.qq.com/cgi-bin/user/cgi_personal_card?ui ...

  6. YII 验证邮箱和QQ号码

    //验证邮箱非空,和邮箱格式                    //验证邮箱非空,和邮箱格式                     array("email","e ...

  7. Java基础知识强化70:正则表达式之引入案例(QQ号码校验)

    1. 校验QQ号码的案例,如下: package cn.itcast_01; import java.util.Scanner; /* * 校验qq号码. * 1:要求必须是5-15位数字 * 2:0 ...

  8. destoon程序中qq号码,手机号,msn必选项实现方法

    最近发现好多客户,信息不完全!还是把qq号码,手机号,msn设为必选项比较好!下面以把qq设为必选项为例找到模板 template/default/member/edit.htm 找到 functio ...

  9. 利用libpcap抓取QQ号码信息

    最近想在QQ登录时把QQ号码信息记录下来,百度了很多都没有找到具体方式,最近用Wireshark分析报文+libpcap库嗅探实现了这个小功能. 通讯背景: QQ客户端在通讯时使用UDP协议,其中数据 ...

随机推荐

  1. http协议与内容压缩

    为了加快网络上的传输的速度,可以将服务器传输的内容进行压缩,服务器的压缩方式有gzip压缩 deflate压缩 compress压缩 content-length:压缩后的长度 如何启动压缩功能 1, ...

  2. Ehcache - hello world

    Key Classes CacheManager The CacheManager class is used to manage caches. Creation of, access to, an ...

  3. 理解Java的引用对象

    SoftReferenceWeakReference 的特性基本一致, 最大的区别在于 SoftReference会尽可能长的保留引用,不会在GC时就回收对象,而是直到JVM 内存不足时才会被回收(虚 ...

  4. 使用html5结构化元素

    显示的效果如上边这样,但是有没有发现内容的外侧没有边线(这个难道是因为浏览器不同吗?有待测试) html5中新增加的元素<header>可以明确的告诉浏览器此处是页头,<nav> ...

  5. html分页

    <div class="fy"> <a href="" title="上一页">上一页</a> < ...

  6. yoga-moblie-res

  7. Redhat 6.5 x64 下载地址

    http://ftp.okhysing.is/ftp/redhat/6.5/isos/x86_64/

  8. js中的referrer返回上一页使用介绍

    js中的referrer的用法举例. js完整代码:  <script language="javascript">  var refer=document.refer ...

  9. ECshop网点程序优化-后台添加类目自动选择上次父类目并计算Sort Order

    如果在ECshop后台批量添加过大量类目的人都能体会到是多么的不方便(这点还是要说一下ECshop的产品经理,细节上还是要多注意),每次添加都需要在几百个类目里面找到要添加的父类目也是一个麻烦事,比如 ...

  10. 支持阻塞操作和轮询操作的globalfifo设备驱动代码分析以及测试代码

    #include <linux/module.h> #include <linux/types.h> #include <linux/fs.h> #include ...