NET中获取HTML代码中的图片集合的类,就像javascript中的document.images
Posted on 2009-02-21 09:57 chaoliu 阅读(263) 评论(0) 编辑 收藏 举报
using mshtml; 这个要你手动添加引用出来 仔细找找。名字我一下也记不得了
然后 获得Ihtmldocument2 接口
IHTMLDocument2 doc = new HTMLDocumentClass();
doc.write(new object[] { html });
doc.close();
再然后就和你用javascript类似了
foreach (IHTMLImgElement image in doc.images)
{
IHTMLElement element = (IHTMLElement)image;
string src = (string)element.getAttribute("src", 2);
if (src != null)
{
//读出属性 这个你没有问题吧?
}
}
然后 获得Ihtmldocument2 接口
IHTMLDocument2 doc = new HTMLDocumentClass();
doc.write(new object[] { html });
doc.close();
再然后就和你用javascript类似了
foreach (IHTMLImgElement image in doc.images)
{
IHTMLElement element = (IHTMLElement)image;
string src = (string)element.getAttribute("src", 2);
if (src != null)
{
//读出属性 这个你没有问题吧?
}
}