【開源】dhtml.net 仿javascript訪問HTML文檔(1.1版)

來源:互聯網
上載者:User

 

本版本為dhtml.net 1.1版,如有疑問請發郵件給我(sqzhuyi@gmail.com)

本版本較1.0版更新如下:

 

1、解決了一些基本BUG

 

2、為Element添加了GetElementsByTagName,GetElementsByName,GetElementsClass方法

 

3、添加document和element的搜尋功能,支援類似jquery搜尋

 

樣本:

string html = @"<p id=p1><span>aaa</span>

<b>bbb</b><textarea><i>af</i></textarea>

<b class='b1'>b1b1b1</b><input type=checkbox /></p>";

 

Document doc = new Document(html);

 

ElementCollect els = doc.Search("#p1 b[class=b1]");

 

 

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擷取該節點
public ElementCollect Search(string path) 搜尋文檔中合格節點,運算式樣本:#div1 span a[class="over"]

 

Element 成員如下:

屬性

public int Index 當前節點在elements集合中的索引
public string Id 節點ID
public string Name 節點name
public string Class 節點class
public string Style 節點style
public string TagName 節點tagName
public AttributeCollect Attributes 節點屬性集合
public string InnerHTML 節點innerHTML
public string OuterHTML 節點outerHTML
public Element PreviousSibling 當前節點的上一個兄弟節點
public Element NextSibling 當前節點的下一個兄弟節點
public Element PreviousElement 當前節點所在集合中的上一個節點
public Element NextElement 當前節點所在集合中的下一個節點
public Element ParentElement 當前節點的父節點
public ElementCollect ChildElements 當前節點的子節點集合

方法

public ElementCollect GetElementsByTagName(string tag) 通過tagName擷取節點集合
public ElementCollect GetElementsByName(string name) 通過節點name屬性擷取節點集合
public ElementCollect GetElementsByClass(string clas) 通過節點class屬性擷取節點集合
public ElementCollect Search(string path) 搜尋文檔中合格節點,運算式樣本:#div1 span a[class="over"]

 

 

源碼下載:

http://download.csdn.net/source/2645389

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.