分析c#获取126邮箱通讯录及解决方案
随着校内网,开心网,海内网等SNS类型的网站的成功,康盛uchome的开源,互联网出现了越来越多的SNS类型的网站,通过获取那些门户网站的邮箱通讯录来邀请会员的技术也得到了广泛的应用.
c#,php获取邮箱通讯录的案例的下载地址 :http://www.eyejs.com/?action-viewnews-itemid-115
现在我就以testsns@126.com邮箱为例来分析126邮箱登陆过程
126的整个登陆过程分5个步骤
步骤
1. http://entry.126.com/cgi/login
虚拟登陆:获取到的页面是:
<html><head></head><body><form name="form1" method="POST" action='http://reg.163.com/logins.jsp' ><input name='type' type='hidden' value='1'><input name='url' type='hidden' value ='http://entry.mail.126.com/cgi/ntesdoor?lightweight%3D1%26verifycookie%3D%26style=%3D%26hid%3D%26bCookie%3D%26RmbUser%3D'><input name='username' type='hidden' value='testsns@126.com'%3E%3Cinput name='password' type='password' value='1234567' style='display:none;'>
<script language='javascript'>form1.submit();</script ></body></html>
2.转调到
https://reg.163.com/logins.jsp?type=1&product=mail126&url=http://entry.mail.126.com/cgi/ntesdoor?hid%3D10010102%26lightweight%3D1%26verifycookie%3D1%26language%3D0%26style%3D-1&username= testsns@126.com&amp;amp;amp;password=密码
获取到的网页是
<html xmlns="http://www.w3.org/1999/xhtml%22%3E%3Chead%3E%3Ctitle>跳转提示</title><style type="text/css"><!--*{margin:0;padding:0;}body{margin:50px;background:#fff;line-height:130%;}div{width:560px;border:5px solid #f5f5f5;padding:10px;}h1{margin:0 0 10px;padding-bottom:10px;border-bottom:1px solid #bbb;font-size:16px;color:blue;font-weight:normal;}h2{font-size:18px;line-height:150%;}p{font-size:14px;}img{margin:10px 0;}a{color:blue;}a:hover{color:red;}--></style></head><body><p id="login_hint" style="visibility : hidden">正在登录...请稍等</p><div id="block_hint" style="visibility : hidden"><h1>如果您看到这个页面,说明您的网速缓慢或者浏览器阻止您在https和http页面间跳转。<br />请您点击<a href="http://passport.126.com/crossdomain.jsp?username=testsns@126.com&loginCookie=fZowZif2M6Mq_2gE8KCQz3vqVfFsouPDVHZm7XSSp.YqkkrONDXewn98kLoAKzujCsI2G30TFdjz.fKNZ2V0ArfnNSa.O0cy0&url=http%3A%2F%2Fentry.mail.126.com%2Fcgi%2Fntesdoor%3Fhid%3D10010102%26lightweight%3D1%26verifycookie%3D1%26language%3D0%26style%3D-1%26username%3Dtestsns%40126.com&loginyoudao=0%22%3E%3Cb%3E%3Cfont color=red>这里</font></strong></a>继续。</h1><h2>温馨提示:</h2><p>从HTTPS页面跳转到HTTP会出现安全提示对话框,这是浏览器本身的设置造成的。如果不希望每次访问HTTPS的站点都有这样的提示,在出现安全提示时请您点“是”,并勾中"以后不再显示该警告"即可。</p></div><script language="JavaScript"><!--setTimeout( function(){ document.getElementById("login_hint").style.visibility = 'visible'; }, 3000);setTimeout( function(){document.getElementById("login_hint").style.visibility = 'hidden'; document.getElementById("block_hint").style.visibility = 'visible'; }, 10000);// --></script><script language="JavaScript">window.location.replace("http://passport.126.com/crossdomain.jsp?username=testsns@126.com&loginCookie=fZowZif2M6Mq_2gE8KCQz3vqVfFsouPDVHZm7XSSp.YqkkrONDXewn98kLoAKzujCsI2G30TFdjz.fKNZ2V0ArfnNSa.O0cy0&url=http%3A%2F%2Fentry.mail.126.com%2Fcgi%2Fntesdoor%3Fhid%3D10010102%26lightweight%3D1%26verifycookie%3D1%26language%3D0%26style%3D-1%26username%3Dtestsns%40126.com&loginyoudao=0%22%29;//remain for popo ,don't del</script><META HTTP-EQUIV=REFRESH CONTENT="0;URL=http://passport.126.com/crossdomain.jsp?username=testsns@126.com&loginCookie=fZowZif2M6Mq_2gE8KCQz3vqVfFsouPDVHZm7XSSp.YqkkrONDXewn98kLoAKzujCsI2G30TFdjz.fKNZ2V0ArfnNSa.O0cy0&url=http%3A%2F%2Fentry.mail.126.com%2Fcgi%2Fntesdoor%3Fhid%3D10010102%26lightweight%3D1%26verifycookie%3D1%26language%3D0%26style%3D-1%26username%3Dtestsns%40126.com&loginyoudao=0"></body></html>
获取Cookie值是:
NTES_SESS=fZowZif2M6Mq_2gE8KCQz3vqVfFsouPDVHZm7XSSp.YqkkrONDXewn98kLoAKzujCsI2G30TFdjz.fKNZ2V0ArfnNSa.O0cy0; path=/; domain=.163.com;,NETEASE_SSN=testsns@126.com; domain=.163.com; path=/; expires=Thu, 07-Jan-2010 01:35:27 GMT,NETEASE_ADV=11&15&1231292128050; domain=.163.com; path=/; expires=Thu, 07-Jan-2010 01:35:27 GMT,URSJESSIONID=aJ04C0MHBlR9; path=/
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>跳转提示</title>
<style type="text/css">
<!--
*{margin:0;padding:0;}
body{margin:50px;background:#fff;line-height:130%;}
div{width:560px;border:5px solid #f5f5f5;padding:10px;}
h1{margin:0 0 10px;padding-bottom:10px;border-bottom:1px solid #bbb;font-size:16px;color:blue;font-weight:normal;}
h2{font-size:18px;line-height:150%;}
p{font-size:14px;}
img{margin:10px 0;}
a{color:blue;}
a:hover{color:red;}
-->
</style>
</head>
<body>
<p id="login_hint" style="visibility : hidden">正在登录...请稍等</p>
<div id="block_hint" style="visibility : hidden">
<h1>如果您看到这个页面,说明网速缓慢或者浏览器阻止了您的页面转向。请您点击<a href="http://entry.mail.126.com/cgi/ntesdoor?hid=10010102&lightweight=1&verifycookie=1&language=0&style=-1&username=testsns@126.com%22%3E%3Cb%3E%3Cfont color=red>这里</font></strong></a>继续。</h1>
</div>
<script language="JavaScript">
<!--
setTimeout( function(){
document.getElementById("login_hint").style.visibility = 'visible';
}, 3000);
setTimeout( function(){
document.getElementById("login_hint").style.visibility = 'hidden';
document.getElementById("block_hint").style.visibility = 'visible';
}, 10000);
// -->
</script>
<script language="JavaScript">
window.location.replace("http://entry.mail.126.com/cgi/ntesdoor?hid=10010102&lightweight=1&verifycookie=1&language=0&style=-1&username=testsns@126.com%22%29;//remain for popo ,don't del
</script>
<META HTTP-EQUIV=REFRESH CONTENT="0;URL=http://entry.mail.126.com/cgi/ntesdoor?hid=10010102&lightweight=1&verifycookie=1&language=0&style=-1&username=testsns@126.com">
</body>
</html>
COOKIE值是
NTES_SESS=rBIJlopubk_IEb7gOOMBEwPJOSVcbXerRi4fhLbbw_50YYtMZOLxdXgCYzkv2yRBU3G96Kl8INBy_r2Z49DlvtrXZbW_Mlnal; path=/; domain=.126.com;,URSJESSIONID=aFXB_zkcV6S6; path=/
4 从第三步获取到的页面代码中获取到url
http://entry.mail.126.com/cgi/ntesdoor?hid=10010102&lightweight=1&verifycookie=1&language=0&style=-1&username=testsns@126.com
获取到页面
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved <a href=" http://tg1a89.mail.126.com/a/j/dm3/main.jsp?sid=rBsiRDeejbFraCvNtneeNbQQlvpoobEe">here</a>.</p>
</body></html>
COOKIE值是
Coremail=XfahuEhRaWqvM%rBsiRDeejbFraCvNtneeNbQQlvpoobEe; path=/; domain=126.com
5从第四步获取到的页面代码中获取到二个数据
url=http://tg1a89.mail.126.com
sid=rBsiRDeejbFraCvNtneeNbQQlvpoobEe 这个sid
string url=string.Format(“{0}/coremail/fcg/ldvcapp?funcid=prtsearchres&sid={1}&listnum=20&tempname=address%2Faddress.htm”,url,sid)
合组成url 再次请求OK,就可以获取到通讯录列表了, 参数listnum显示每页显示多少条通讯录记录,0代表不分页,全部显示
抓取到的页面数据显示如下,
<!-- address/address.htm 通讯录 联系人-->
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="JavaScript" src="http://mimg.163.com/dmstyle/js/samedomain.js%22%3E%3C/script>
<script language="JavaScript">
<!--
function fLoadData(){
try{
var jsFrame = window.parent.parent.frames["jsFrame"];
jsFrame.CM[ name ] = obj;
jsFrame.MM.createModule( name );
}catch(e){}
}
var name= "address";
var obj = new Object();
obj.page= new Array();
obj.row = new Array();
obj.grouping = new Array();
obj.a = new Array();
obj.a["add"] = "/coremail/fcg/ldvcapp?funcid=loadiadd&sid=RBgoWMmmddIpWkDuyfmmLjdramxcGXfm&ifirstv=&showlist=&add.x=1";
obj.a["sortN"] = "/coremail/fcg/ldvcapp?funcid=prtsearchres&sid=RBgoWMmmddIpWkDuyfmmLjdramxcGXfm&sortattr_N=&showlist=&ifirstv=";
obj.a["sortE"] = "/coremail/fcg/ldvcapp?funcid=prtsearchres&sid=RBgoWMmmddIpWkDuyfmmLjdramxcGXfm&sortattr_EMAIL;PREF=&showlist=&ifirstv=";
obj.a["find"] = "/coremail/fcg/ldvcapp?funcid=prtsearchres&sid=RBgoWMmmddIpWkDuyfmmLjdramxcGXfm&tempname=address/address.htm&showlist=&ifirstv=";
obj.img = new Array();
obj.img["sortN"]= '';
obj.img["sortE"]= '';
var i , xmp;
String.prototype.trim = function(){
return this.replace(/(^\s*)|(\s*)/g, "");
}
//-->
</script>
</head><body>
<xmp id="hide_form">
<input type="hidden" name="sid" value="RBgoWMmmddIpWkDuyfmmLjdramxcGXfm" >
<input type="hidden" name="ifirstv" value="">
</xmp>
<xmp id="hide_gform">
<input type="hidden" name="sid" value="RBgoWMmmddIpWkDuyfmmLjdramxcGXfm" >
<input type="hidden" name="postid" value="2498811901231292559" >
<input type="hidden" name="lid" value="" >
<input type="hidden" name="group" value="" >
<input type="hidden" name="ifirstv" value="" >
</xmp>
<form>
<select name="listnum">
<option value="0" >不分页</option>
<option value="10" >每页10项</option>
<option value="20" selected >每页20项</option>
<option value="50" >每页50项</option>
<option value="100" >每页100项</option>
</select>
<select name="grplist">
<option value="Address_SysGroupName"> </option><option value="FRIENDS">朋友 </option><option value="FAMILY">亲人 </option><option value="COWORKERS">同事 </option><option value="NETFRIENDS">网友 </option><option value="RECENT">常用联系人 </option>
</select>
</form>
<xmp id="gname">
</xmp>
<xmp id="t 1">测试1<space>test1@163.com</xmp>
<script language="JavaScript">
xmp = document.getElementById("t 1");
xmp = xmp.innerHTML.split("<space>");
i = 1 - 1;
obj.row[i] = new Object();
obj.row[i].chkname = "chk-_0_0_";
obj.row[i].chkvalue = "test1%40163.com";
obj.row[i].iname = xmp[0];
obj.row[i].iemail = xmp[1];
obj.row[i].asend = "/coremail/fcg/ldmmapp?sid=RBgoWMmmddIpWkDuyfmmLjdramxcGXfm&funcid=compose&to=%22%B2%E2%CA%D41%22%20%3Ctest1%40163.com%3E";
obj.row[i].afind = "/coremail/fcg/ldsrchapp?funcid=srchhand&sid=RBgoWMmmddIpWkDuyfmmLjdramxcGXfm&word=test1%40163.com&fromonly=yes&fid=0&subfolder=yes&perfectmatch=1&rtnurl=%2Fcoremail%2Ffcg%2Fldvcapp%3Ffuncid%3Dprtsearchres%26sid%3DRBgoWMmmddIpWkDuyfmmLjdramxcGXfm%26listnum%3D20%26tempname%3Daddress%252Faddress.htm%26total%3D3";
obj.row[i].ainfo = "/coremail/fcg/ldvcapp?funcid=prtsearchres&sid=RBgoWMmmddIpWkDuyfmmLjdramxcGXfm&iid=0&mode=1&emptymode=1&print.x=1&tempname=address/add.htm";
obj.row[i].aedit = "/coremail/fcg/ldvcapp?funcid=loadiadd&iid=0&sid=RBgoWMmmddIpWkDuyfmmLjdramxcGXfm&ifirstv=&lid=&modify.x=1";
obj.row[i].grouping = "";
obj.row[i].iid = i;
</script>
<xmp id="t 2">张三<space>test2@163.com</xmp>
<script language="JavaScript">
xmp = document.getElementById("t 2");
xmp = xmp.innerHTML.split("<space>");
i = 2 - 1;
obj.row[i] = new Object();
obj.row[i].chkname = "chk-_0_1_";
obj.row[i].chkvalue = "test2%40163.com";
obj.row[i].iname = xmp[0];
obj.row[i].iemail = xmp[1];
obj.row[i].asend = "/coremail/fcg/ldmmapp?sid=RBgoWMmmddIpWkDuyfmmLjdramxcGXfm&funcid=compose&to=%22%D5%C5%C8%FD%22%20%3Ctest2%40163.com%3E";
obj.row[i].afind = "/coremail/fcg/ldsrchapp?funcid=srchhand&sid=RBgoWMmmddIpWkDuyfmmLjdramxcGXfm&word=test2%40163.com&fromonly=yes&fid=0&subfolder=yes&perfectmatch=1&rtnurl=%2Fcoremail%2Ffcg%2Fldvcapp%3Ffuncid%3Dprtsearchres%26sid%3DRBgoWMmmddIpWkDuyfmmLjdramxcGXfm%26listnum%3D20%26tempname%3Daddress%252Faddress.htm%26total%3D3";
obj.row[i].ainfo = "/coremail/fcg/ldvcapp?funcid=prtsearchres&sid=RBgoWMmmddIpWkDuyfmmLjdramxcGXfm&iid=1&mode=1&emptymode=1&print.x=1&tempname=address/add.htm";
obj.row[i].aedit = "/coremail/fcg/ldvcapp?funcid=loadiadd&iid=1&sid=RBgoWMmmddIpWkDuyfmmLjdramxcGXfm&ifirstv=&lid=&modify.x=1";
obj.row[i].grouping = "";
obj.row[i].iid = i;
</script>
<xmp id="t 3">李则<space>test4@163.com</xmp>
<script language="JavaScript">
xmp = document.getElementById("t 3");
xmp = xmp.innerHTML.split("<space>");
i = 3 - 1;
obj.row[i] = new Object();
obj.row[i].chkname = "chk-_0_2_";
obj.row[i].chkvalue = "test4%40163.com";
obj.row[i].iname = xmp[0];
obj.row[i].iemail = xmp[1];
obj.row[i].asend = "/coremail/fcg/ldmmapp?sid=RBgoWMmmddIpWkDuyfmmLjdramxcGXfm&funcid=compose&to=%22%C0%EE%D4%F2%22%20%3Ctest4%40163.com%3E";
obj.row[i].afind = "/coremail/fcg/ldsrchapp?funcid=srchhand&sid=RBgoWMmmddIpWkDuyfmmLjdramxcGXfm&word=test4%40163.com&fromonly=yes&fid=0&subfolder=yes&perfectmatch=1&rtnurl=%2Fcoremail%2Ffcg%2Fldvcapp%3Ffuncid%3Dprtsearchres%26sid%3DRBgoWMmmddIpWkDuyfmmLjdramxcGXfm%26listnum%3D20%26tempname%3Daddress%252Faddress.htm%26total%3D3";
obj.row[i].ainfo = "/coremail/fcg/ldvcapp?funcid=prtsearchres&sid=RBgoWMmmddIpWkDuyfmmLjdramxcGXfm&iid=2&mode=1&emptymode=1&print.x=1&tempname=address/add.htm";
obj.row[i].aedit = "/coremail/fcg/ldvcapp?funcid=loadiadd&iid=2&sid=RBgoWMmmddIpWkDuyfmmLjdramxcGXfm&ifirstv=&lid=&modify.x=1";
obj.row[i].grouping = "";
obj.row[i].iid = i;
</script>
<script language="JavaScript">
<!--
var arr = document.forms[0].grplist.options;
for(var i=0,j=0;i<arr.length;i++){
if(arr[i].value!="Address_SysGroupName"){
obj.grouping[j] = [arr[i].value,arr[i].text,arr[i].text.trim()];
j++;
}
}
obj.hide_form = document.getElementById("hide_form").innerHTML;
obj.hide_gform = document.getElementById("hide_gform").innerHTML;
obj.listnum = document.forms[0].listnum.value;
obj.gname = document.getElementById("gname").innerHTML;
fLoadData();
//-->
</script>
</body></html>
<!-- CoreMail Version 3.1_snapshot Copyright (c) 2002-2009 http://www.mailtech.cn/ -->
案例下载: emailcontactexp.rar
水平有限,写得不好,请多多包涵 如有交流:请到http://www.eyejs.com/?action-viewnews-itemid-115