I have made this source code open-source before, and I did it again last night. Open source code. Here we will talk about the ideas and real source code implementation. We will use one classHttpclientFor the basic usage of this class, refer:
Http://www.ibm.com/developerworks/cn/opensource/os-httpclient/
We will use httpclient and httpwatch tools.
Watch can be available in http://www.ij2ee.com/what-to-use-to-develop.
Official start:
First, we use our account password to log on to the thieftest password a123456 for the convenience of others. Do not change the password.
In order to quickly find the corresponding request address, we directly search for our user name
We get 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
We can see that this string is a POST request, so we need to use the httpclient POST request to request the server. The core of post and get requests is as follows:Code
Public static string doget (httpclient client, string URL, string charcode) throws urisyntaxexception, illegalstateexception, ioexception, httpexception, interruptedexception {httpget get = new httpget (URL ); return stringutil.readinputstream(client.exe cute (get ). getentity (). getcontent (), charcode);} public static string dopost (httpclient client, string URL, Map <string, string> param, string charcode) Throw S urisyntaxexception, illegalstateexception, ioexception, httpexception, interruptedexception {namevaluepair nvps [] = new basicnamevaluepair [Param. size ()]; int I = 0; For (map. entry <string, string> entry: Param. entryset () {namevaluepair NVP = new basicnamevaluepair (entry. getkey (), entry. getvalue (); nvps [I ++] = NVP;} httppost = new httppost (URL); httppost. setentity (New urlencodedformentity (NV PS, charcode); httpresponse response = client.exe cute (httppost); If (response. getstatusline (). getstatuscode ()! = 200) {Throw new runtimeexception ("webpage capture failed, HTTP Code:" + response. getstatusline (). getstatuscode ();} inputstream is = response. getentity (). getcontent (); Return stringutil. readinputstream (is, charcode );}
Based on the returned information, we can determine whether the analysis is successful or not by checking whether a parameter named Sid is obtained.
If the returned result is successful, will there be an index in the message? SID = XXXXXXXXX.Xxxxxxx here is crucial, We need to get him. Here we can use regular expressions. To obtain the approximate code:
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 ;}
After the dot communication, we captured the packet and found that a URL seems to be in the record.
Is the JSON. If there is more data, we can view the directory structure on www.bejson.com.
But when we request this URL, we find it returns
<? XML version = "1.0" encoding = "UTF-8"?> -<Result> <code> s_ OK </code> </result>
It seems that this road is broken. Continue to search for a record. Suddenly we found that there were printing operations to get all the information we wanted.
String getusers = "http://tg4a84.mail.163.com/jy3/address/addrprint.jsp? SID = the ID obtained earlier ";
Get the following content after the request
< 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 > & Nbsp; < Span Style = "Font-size: 16px" > Select the project to print </ Span > </ B > & Nbsp; < Input Type = "Checkbox" Name = "Phone" Value = "Phone" Onclick = "Faddressprintshow (this )" > Phone/instant messaging ID < Input Type = "Checkbox" Name = "Home" Value = "Home" Onclick = "Faddressprintshow (this )" > Household Information < Input Type = "Checkbox" Name = "Company" Value = "Company" Onclick = "Faddressprintshow (this )" > Organization/Company < Input Type = "Checkbox" Name = "Other" Value = "Other" Onclick = "Faddressprintshow (this )" > Other information </ 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 = "Print" Style = "Margin-bottom: 8px" Onclick = "Window. Print ();" /> </ Span > </ Div > </ TD > </ Tr > </ Table > < Div Class = "HR" > < HR /> </ Div > < Div Class = "Gtitlesub" > < Div Align = "Left" > < B Class = "MTT" > Sanshao </ B > </ Div > < Div Class = "Extra" > </ Div > </ Div > < Table Class = "Gtable" > < Tr ID = "Tr_base_0" Style = "" > < Th > Email Address: </ Th > < TD > Ij2ee@139.com </ TD > </ Tr > < Tr ID = "Tr_base_0" Style = "" > < Th > Mobile phone: </ Th > < TD > </ TD > </ Tr > < Tr ID = "Tr_base_0" Style = "" > < Th > Birthday: </ Th > < TD > </ TD > </ Tr > < Tr ID = "Tr_home_2" Style = "Display: none" > < Th > Contact address: </ Th > < TD > China </ TD > </ Tr > < Tr ID = "Tr_company_3" Style = "Display: none" > < Th > Company address: </ Th > < TD > ; Ci </ TD > </ Tr > < Tr ID = "Tr_other_4" Style = "Display: none" > < Th > Note: </ Th > < TD > Java blog www.ij2ee.com </ TD > </ Tr > </ Table > < Div Class = "HR" > < HR /> </ Div > < Div Class = "Gtitle" > < Div Align = "Center" > < Span Style = "Color: #999 ;" > Copyright of Netease </ Span > </ Div > </ Div > </ Div > </ Div >
The parsing is left below.
For details, seeSource code.
Source code download: http://115.com/file/bejbru4y#thief.rar contains the source code and jar package can be run, there are test cases in the test package
Source: http://www.ij2ee.com/49657.html