請訪問dhtml.net 1.1版:
http://blog.csdn.net/sq_zhuyi/archive/2010/06/26/5695397.aspx
相信很多朋友都為解析HTML源碼犯過愁,在社區裡也經常看到有人提此類問題,
今天工作少,索性做了個解析HTML文檔的萬用群組件,用法如下:
string url = "http://www.baidu.com/";//此處可以是一個URL,也可以是一段HTML字串
Document doc = new Document(url);
Console.WriteLine(doc.Title);
Console.WriteLine(doc.GetElementById("u").InnerHTML);
輸出結果:
百度一下,你就知道
<a href="http://passport.baidu.com/?login&tpl=mn">登入</a>
Document 成員如下:
屬性
public ElementCollect Elements |
擷取HTML文檔中的所有節點 |
public Element Body |
擷取body節點 |
public string Title |
擷取文檔title字串 |
public FormCollect Forms |
擷取文檔中所有form節點 |
public FrameCollect Frames |
擷取文檔中所有frame節點 |
public ScriptCollect Scripts |
擷取文檔中所有script元素 |
public ImageCollect Images |
擷取文檔中所有img元素 |
方法
public ElementCollect GetElementsByTagName(string tag) |
通過tagName擷取節點集合 |
public ElementCollect GetElementsByName(string name) |
通過節點name屬性擷取節點集合 |
public ElementCollect GetElementsByClass(string clas) |
通過節點class屬性擷取節點集合 |
public Element GetElementById(string id) |
通過節點id擷取該節點 |
源碼下載:
http://files.cnblogs.com/sqzhuyi/Dhtml.net-src(1.1).zip