Htmlagilitypack Study and notes

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.