【发布时间】:2011-03-27 01:16:39
【问题描述】:
我一直在尝试使用此代码在 html/ajax 中按类读取元素,因为我知道 GetElementByClass 不是 webBrowser.Document 中的选项。我似乎无法获得返回值然后调用该成员。有解决办法吗?
参考资料: 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.
}
}
【问题讨论】:
标签: c# html ajax browser webbrowser-control