1. 程式人生 > >用IHTMLDocument2接口獲取頁面上想要的數據,代替正則表達式

用IHTMLDocument2接口獲取頁面上想要的數據,代替正則表達式

正則表達式 導入 innertext close lose doc html con HA

原文:用IHTMLDocument2接口獲取頁面上想要的數據,代替正則表達式

原文發布時間為:2010-07-01 —— 來源於本人的百度文章 [由搬家工具導入]

1. 用 IHTMLDocument2::all 获得所有元素;
2. 用 IHTMLElementCollection::tags 获得标签为 span 的元素;
3. 用 IHTMLElement::className 获得 class 名为 EX 的元素;
4. 用 IHTMLElement::innerText 获得文本。

IHTMLDocument2 doc = new HTMLDocumentClass();
doc.write(new object[] { ie.OutString });
doc.close();
if (doc != null)
{
IHTMLElementCollection iec = (IHTMLElementCollection)doc.all.tags("dd");

foreach (IHTMLElement ii in iec)
{
if (ii.getAttribute("onmouseout", 0).ToString() != "")
{
Console.WriteLine(ii.innerText);
string str = ii.innerText;
}
}
}

用IHTMLDocument2接口獲取頁面上想要的數據,代替正則表達式