Dhtml.net accessing HTML documents using JavaScript-like

Source: Internet
Author: User

Please visit dhtml.net 1.1:

Http://blog.csdn.net/sq_zhuyi/archive/2010/06/26/5695397.aspx

 

I believe many of my friends have been worried about parsing the HTML source code. In the community, I often see people asking such questions,

Today, I am working little and simply made a general component for parsing HTML documents. The usage is as follows:

 

 

String url = "http://www.baidu.com/"; // This can be a URL or an HTML string

Document Doc = new document (URL );

Console. writeline (Doc. Title );

 

Console. writeline (Doc. getelementbyid ("U"). innerhtml );

 

 

Output result:

Baidu, you will know

 

<A href = "http://passport.baidu.com /? Login & TPL = Mn "> logon </a>

 

The document members are as follows:

Attribute

Public elementcollect Elements Retrieve all nodes in the HTML document
Public element body Get body Node
Public String title Obtain the document title string
Public formcollect forms Retrieve all form nodes in the document
Public framecollect Frames Retrieve all frame nodes in the document
Public scriptcollect scripts Obtain all script elements in the document
Public imagecollect Images Retrieve all IMG elements in the document

Method

Public elementcollect getelementsbytagname (string tag) Get node set by tagname
Public elementcollect getelementsbyname (string name) Get the node set through the node name attribute
Public elementcollect getelementsbyclass (string CLAS) Get the node set through the node class attribute
Public element getelementbyid (string ID) Obtain the node ID

 

Download source code:

Http://files.cnblogs.com/sqzhuyi/Dhtml.net-src (1.1).zip

 

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.