我一直試圖使用此代碼通過html/ajax中的類讀取元素,因爲知道GetElementByClass不是webBrowser.Document中的選項。我似乎無法獲得返回值,然後調用該成員。有沒有解決這個問題的方法?如何通過GetElementByClass選擇一個類,然後通過編程點擊它
參考文獻: Getting HTMLElements by Class Name
例子:
<span class="example">(<a href="http://www.test.com/folder/remote/api?=test" onclick=" return do_ajax('popup_fodder', 'remote/api?=test', 1, 1, 0, 0); return false; " class="example">test</a>)</span>
示例代碼:
HtmlElementCollection theElementCollection = default(HtmlElementCollection);
theElementCollection = webBrowser1.Document.GetElementsByTagName("span");
foreach (HtmlElement curElement in theElementCollection)
{
//If curElement.GetAttribute("class").ToString = "example" It doesn't work.
// This should be the work around.
if (curElement.OuterHtml.Contains("example"))
{
MessageBox.Show(curElement.GetAttribute("InnerText")); // Doesn't even fire.
// InvokeMember(test) after class is found.
}
}
真棒,叉子jQuery的? ;) – 2010-08-09 03:33:35
Messagebox.Show將顯示它檢索到的文本。 JQuery我不熟悉。在這種情況下有一個例子嗎? – Nightforce2 2010-08-10 20:04:57