我想在此代码中获取文本:
<div class="js-text-container"></div>
当有ID时,我使用getelementbyId,没问题,但是在这种情况下没有ID,甚至没有任何内部的2&gt;&lt; (虽然有东西显示)
我找到了一个有趣的解决方案here并试图让它适应我的情况:
Dim divs = WebBrowser1.Document.Body.GetElementsByTagName("div")
For Each d As HtmlElement In divs
If d.GetAttribute("class") = "js-text-container" Then
TextBox1.Text = d.InnerText
End If
Next
但我的文本框中没有任何内容。有人有想法吗?我认为这是因为InnerText
在这种情况下没有提到......
我希望我很清楚。
非常感谢
答案 0 :(得分:2)
而不是d.GetAttribute("class") = "js-text-container"
使用
d.GetAttribute("className") = "js-text-container"
我在本地测试过,我相信你可以在VB.Net中使用它
foreach (HtmlElement el in webBrowser1.Document.GetElementsByTagName("div"))
if (el.GetAttribute("className") == "js-text-container")
{
textBox1.Text = el.InnerText;
}
希望它有所帮助!