dhtml.net 仿javascript訪問HTML文檔

來源:互聯網
上載者:User

請訪問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

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.