09-10
22
QQ号码采集代码(PHP)
作者:Java伴侣 日期:2009-10-22
通过QQ.COM上的QQ空间里的找朋友功能,设置年龄,性别等找到符合的QQ空间,解析出QQ号码。
-------- const.php -------------------
<?php
/*SEX*/
define("SEX_MAN","1");
define("SEX_WOMAN","2");
define("SEX_UNDEFINED","-1");
/*MARRAY*/
define("MR_YES","2");
define("MR_NO","1");
define("MR_UNDEFINED","-1");
?>
---------- func_lib.php --------------
<?php
require_once('const.php');
function build_search_url($begin,$sex = SEX_UNDEFINED, $age_s = -1, $age_e = -1, $is_m = MR_UNDEFINED)
{
$s_url =
"http://soren.qzone.qq.com/cgi-bin/soren/cgi_userinfo_search?sex={$sex}&a1={$age_s}&a2={$age_e}&pv=0&ct=0&mr={$is_m}&nn=&interest=&begin={$begin}&bSimple=1";
return $s_url;
}
function get_match_qq_num(&$data)
{
$matchs = array();
$numString1 = "";
$pattern = "/(<strong>(.*[^<])<\/strong>条结果)/";
if(preg_match_all($pattern,$data,$matchs) != 0 || preg_match_all($pattern,$data,$matchs) != FALSE)
{
$numString1 = $matchs[1][1];
$numString1 = qq_num_str2int($numString1);
return intval($numString1);
}
else
{
return 0;
}
}
function qq_num_str2int(&$str)
{
$v = array();
$vv = "";
$v = split(',',$str);
foreach($v as $s)
{
$vv .= $s;
}
return $vv;
}
function get_qq_mail(&$data)
{
$matchs = array();
$pattern = "/http:\/\/user\.qzone\.qq\.com\/(\d*)/";
$qq_number_num = 0;
$qq_mail = array();
if(($qq_number_num = preg_match_all($pattern,$data,$matchs) ) != FALSE)
{
for($i = 0; $i < $qq_number_num; $i ++)
{
$qq_mail[] = $matchs[1][$i]."@qq.com";
}
}
return array_unique($qq_mail);
}
function print_qq_mail(&$mails)
{
foreach($mails as $mail)
{
echo $mail."\r\n";
}
}
?>
--------- qq_mail.php ------------------
<?php
require_once('func_lib.php');
require_once('const.php');
$s_url = build_search_url(0,SEX_WOMAN,28,40,MR_UNDEFINED);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$s_url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
$page = curl_exec($ch);
$qq_num = get_match_qq_num($page);
$qq_mail = get_qq_mail($page);
print_qq_mail($qq_mail);
for($i = 1; $i < ($qq_num / 10); $i ++)
{
$s_url = build_search_url($i,SEX_WOMAN,28,40,MR_UNDEFINED);
curl_setopt($ch,CURLOPT_URL,$s_url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
$page = curl_exec($ch);
$qq_mail = get_qq_mail($page);
print_qq_mail($qq_mail);
}
curl_close($ch);
?>
-------- const.php -------------------
<?php
/*SEX*/
define("SEX_MAN","1");
define("SEX_WOMAN","2");
define("SEX_UNDEFINED","-1");
/*MARRAY*/
define("MR_YES","2");
define("MR_NO","1");
define("MR_UNDEFINED","-1");
?>
---------- func_lib.php --------------
<?php
require_once('const.php');
function build_search_url($begin,$sex = SEX_UNDEFINED, $age_s = -1, $age_e = -1, $is_m = MR_UNDEFINED)
{
$s_url =
"http://soren.qzone.qq.com/cgi-bin/soren/cgi_userinfo_search?sex={$sex}&a1={$age_s}&a2={$age_e}&pv=0&ct=0&mr={$is_m}&nn=&interest=&begin={$begin}&bSimple=1";
return $s_url;
}
function get_match_qq_num(&$data)
{
$matchs = array();
$numString1 = "";
$pattern = "/(<strong>(.*[^<])<\/strong>条结果)/";
if(preg_match_all($pattern,$data,$matchs) != 0 || preg_match_all($pattern,$data,$matchs) != FALSE)
{
$numString1 = $matchs[1][1];
$numString1 = qq_num_str2int($numString1);
return intval($numString1);
}
else
{
return 0;
}
}
function qq_num_str2int(&$str)
{
$v = array();
$vv = "";
$v = split(',',$str);
foreach($v as $s)
{
$vv .= $s;
}
return $vv;
}
function get_qq_mail(&$data)
{
$matchs = array();
$pattern = "/http:\/\/user\.qzone\.qq\.com\/(\d*)/";
$qq_number_num = 0;
$qq_mail = array();
if(($qq_number_num = preg_match_all($pattern,$data,$matchs) ) != FALSE)
{
for($i = 0; $i < $qq_number_num; $i ++)
{
$qq_mail[] = $matchs[1][$i]."@qq.com";
}
}
return array_unique($qq_mail);
}
function print_qq_mail(&$mails)
{
foreach($mails as $mail)
{
echo $mail."\r\n";
}
}
?>
--------- qq_mail.php ------------------
<?php
require_once('func_lib.php');
require_once('const.php');
$s_url = build_search_url(0,SEX_WOMAN,28,40,MR_UNDEFINED);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$s_url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
$page = curl_exec($ch);
$qq_num = get_match_qq_num($page);
$qq_mail = get_qq_mail($page);
print_qq_mail($qq_mail);
for($i = 1; $i < ($qq_num / 10); $i ++)
{
$s_url = build_search_url($i,SEX_WOMAN,28,40,MR_UNDEFINED);
curl_setopt($ch,CURLOPT_URL,$s_url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
$page = curl_exec($ch);
$qq_mail = get_qq_mail($page);
print_qq_mail($qq_mail);
}
curl_close($ch);
?>
评论: 0 | 引用: 0 | 查看次数: 458
发表评论