日期:2009-07-18  浏览次数:20993 次

前几天写一个程序,需要后台遍历一个动态生成的页面,找寻特定节点

于是写了以下代码:

public class HTMLReader
{
public HTMLReader()
{
}
///
/// 搜索特定标记的节点
///
///
///
/// 返回属性值数组
public static ArrayList SearchAttributes(string inMarkup, string Keyword, string AttrName)
{
IHTMLDocument2 doc = new HTMLDocumentClass ();
doc.write (new object [] {inMarkup});
doc.close ();
ArrayList searchList = new ArrayList();

foreach(IHTMLElement el in (IHTMLElementCollection)doc.body.all)
{
if(el.tagName.ToLower() ==Keyword)
{
string src=../../el.getAttribute(AttrName,0).ToString();
//src=../../src.Remove(0,src.LastIndexOf("/")+1);
searchList.Add(src);
}
}
return searchList;
}

}