Introduced:
Http://www.cnblogs.com/bomo/archive/2013/01/28/2879361.html
Actual Combat C # get extranet IP
Website: http://ip138.com/
Analysis
There is an IFRAME actually viewing the Web page source code is not the reason why the browser engine resolves the src address:
So we first get the URL of the IFRAME at this address to take the IP (of course, some people say it is not good to use the URL directly?)
Code:
Static voidMain (string[] args) { stringContent = Gethtmlstr ("http://www.ip138.com/", Encoding.GetEncoding ("gb2312")); varULR =""; HTMLDocument Document=NewHTMLDocument (); Document. loadhtml (content); Htmlnodecollection targetnodecollection= document. Documentnode.selectnodes (@"//iframe [1]");//take an iframe DOM first if(Targetnodecollection! =NULL&& Targetnodecollection.count = =1) {ULR= targetnodecollection[0]. Getattributevalue ("src","");//similar to JQ $ (XXX). attr ("SCR") corresponds to JavaScript getattribute} content= Gethtmlstr (ULR, Encoding.GetEncoding ("gb2312")); Document. loadhtml (content); Htmlnodecollection Temptext= document. Documentnode.selectnodes (@"//center [1]");//take center DOM firstConsole.WriteLine (temptext[0]. InnerText);//There 's no filtering here. } Public Static stringGETHTMLSTR (stringURL, Encoding en) { Try{WebRequest Rget=webrequest.create (URL); Rget.timeout=30000; using(WebResponse RSet =Rget.getresponse ()) { using(StreamReader reader =NewStreamReader (Rset.getresponsestream (), en)) { returnReader. ReadToEnd (); } } } Catch(webexception) {//Connection Failed return NULL; } }
Results: