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