我一直试图使用此代码通过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