一对一免费咨询: 13913005726 025-66045668

这个源码我之前开源过,昨晚又做了一下。公开源码。这里讲下思路以及真实源码实现。我们将使用1个类HttpClient,这个类的基本用法可以参照:

http://www.ibm.com/developerworks/cn/opensource/os-httpclient/

我们会使用httpClient以及Httpwatch工具。

正式开始:

首先,我们用我们的账户密码登录,这里是thieftest 密码a123456 为了他人方便,请不要修改密码

为了更快的找到对应的请求地址,我们直接搜索我们的用户名

我们获取了 https://ssl.mail.163.com/entry/coremail/fcg/ntesdoor2?df=webmail163&from=web&funcid=loginone&iframe=1&language=-1&net=t&passtype=1&product=mail163&race=234_62_188_db&style=-1&uid=thieftest@163.com

这么一串字符串 ,我们可以看到它是一个POST请求,所以我们需要用httpclient的POST请求来请求服务器。

下面是POST和GET请求的核心代码,

public static String doGet(span class="wp_keywordlink_affiliate"a href="http://www.ij2ee.com/tag/httpclient" title="查看 HttpClient 中的全部文章" target="_blank"HttpClient/a/span client, String url, String charCode)
throws URISyntaxException, IllegalStateException, IOException,
HttpException, 公司网站建设 InterruptedException {
HttpGet get = new HttpGet(url);
return StringUtil.readInputStream(client.execute(get).getEntity()
.getContent(), charCode);
}
public static String doPost(span class="wp_keywordlink_affiliate"a href="http://www.ij2ee.com/tag/httpclient" title="查看 HttpClient 中的全部文章" target="_blank"HttpClient/a/span client, String url,
MapString, String param, String charCode)
throws URISyntaxException, IllegalStateException, IOException,
HttpException, InterruptedException {
NameValuePair nvps[] = new BasicNameValuePair[param.size()];
int i = 0;
for (Map.EntryString, String entry : param.entrySet()) {
NameValuePair nvp = new BasicNameValuePair(entry.getKey(), entry
.getValue());
nvps[i++] = nvp;
}
HttpPost 临汾网站建设公司 httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(nvps, charCode));
HttpResponse response = client.execute(httpPost);
if(response.getStatusLine().getStatusCode()!=200){
throw new RuntimeException("网页抓取失败,HTTP CODE:"+response.getStatusLine().getStatusCode());
}
InputStream is = response.getEntity().getContent();
return StringUtil.readInputStream(is, charCode);
}

根据返回的信息我们分析成功与否,判断的方式就是看有没得到一个叫sid的参数

返回成功的话 会在消息里有 index?sid=xxxxxxxxx 这一段。 这里的xxxxxxx是至关重要的,我们需要获取他。 这里我们可以使用正则表达式。来获取 大概代码如下:

private static String 外企网站建设公司 regex = "iframe src=\"index.jsp\\?sid=([^\"]+)";
public static String getByRegex(String regex, int index, String txt) {
Pattern p = Pattern.compile(regex,Pattern.DOTALL);
Matcher m = p.matcher(txt);
if (m.find()) {
return m.group(index);
}
return null;
}

点通讯后 我们抓包发现了一个URL 貌似记录都在里面。

是JSON的撒。要是数据多了 福州网站建设公司 我们可以在www.bejson.com 上查看目录结构

但是我们请求这个URL后 发现它就返回了

?xml version="1.0" encoding="UTF-8" ?
result
codeS_OK/code
/result

看来这条路不通啊。继续找把。忽然发现还有打印的操作能得到所有的我们想要的资料。

String getUsers="http://tg4a84.mail.163.com/jy3/address/addrprint.jsp?sid=前面获取的ID";

请求后得到如下内容

div class="ContentWp add_print2"
div class="ContentThemeWp"
table width="100%" height="35px" border="0" cellpadding="0" cellspacing="0" bgcolor="f0f9fc"
tr
td width="88%"b    span style=" font-size:16px"选择打印的项目/span/b input type="checkbox" name="phone" value="phone" onclick="fAddressPrintShow(this)"电话/即时通讯IDinput type="checkbox" name="home" value="home" onclick="fAddressPrintShow(this)"家庭资料input type="checkbox" name="company" value="company" onclick="fAddressPrintShow(this)"单位/公司input type="checkbox" name="other" value="other" onclick="fAddressPrintShow(this)"其他信息/span/td
td width="12%"div align="center"span style="background-color:#f0f9fc; height:35px; padding-top:8px"input name="button" type="button" class="Btn BtnNml ImpBtn" onMouseOver="this.className='Btn BtnHv ImpBtn'" onMouseOut="this.className='Btn BtnNml ImpBtn'" onMouseDown="this.className='Btn BtnHv BtnDw ImpBtn'" hidefocus="ture" value="打 印" style=" margin-bottom:8px" onclick="window.print();"//span/div/td
/tr
/table
div class="Hr"hr/
/divdiv class="gTitleSub"div align="left"b class="mTT"三少/b/divdiv class="Extra"/div/div
table class="gTable"tr id="tr_base_0" style=""th邮件地址:/thtdij2ee@139.com/td/trtr id="tr_base_0" style=""th移动电话:/thtd/td/trtr id="tr_base_0" style=""th生日:/thtd/td/trtr id="tr_home_2" style="display:none"th联系地址:/thtdChina 中国/td/trtr id="tr_company_3" style="display:none"th公司地址:/thtd;;;;;;CI/td/trtr id="tr_other_4" style="display:none"th备注:/thtdJava技术博客 www.ij2ee.com/td/tr
/table
div class="Hr"hr //divdiv class="gTitle"div align="center"span style="color:#999;"网易公司版权所有/span/div/div
/div
/div

下面就剩下解析了。

具体的看源代码。

源码下载:http://115.com/file/bejbru4y#thief.rar 包含源码及jar包 下下来就可以跑,在test包里有测试用例

本文来源:http://www.ij2ee.com/49657.html


 


 南京牧狼文化传媒有限公司简介:


      牧狼传媒,牧者之心,狼者之性,以牧之谦卑宽容之心待人,以狼之团结无畏之性做事!


  公司注册资金100万,主营众筹全案服务、网站营销全案服务、网站建设、微信小程序开发、电商网店设计、H5页面设计、腾讯社交广告投放以及电商营销推广全案等相关业务,致力于为客户提供更有价值的服务,创造让用户满意的效果!


  为百度官方及其大客户、苏宁易购、金山WPS秀堂、美的、创维家电、新东方在线、伊莱克斯、宝丽莱等国内国外知名品牌服务过,服务经验丰富!同时,公司也是南京电子商务协会会员单位、猪八戒网官方认证签约服务商、江苏八戒服务网联盟、南京浦口文化产业联合会会员单位,可以为您提供更好的服务!


  主营项目:众筹全案服务、网站营销全案服务、网站建设、微信小程序开发、电商网店设计、H5页面设计、腾讯社交广告投放、竞价托管、网站优化、电商代运营等


  合作客户:百度、苏宁易购、饿了么、美的、创维家电、新东方在线、宝丽莱、金山WPS秀堂、伊莱克斯


  资质荣誉:百度商业服务市场2017年度最佳图片服务商、南京电子商务协会会员单位、猪八戒网官方认证签约服务商、江苏八戒服务网联盟、南京浦口文化产业联合会会员单位、八戒通TOP服务商、"易拍即合杯"H5创意大赛"三等奖"。



致力于为客户创造更多价值
13913005726 025-66045668
需求提交
电话咨询
在线咨询