Reputation: 75
I would like to get the text inside this code:
<div class="js-text-container"></div>
when there is an ID, i use getelementbyId, no problem, but in this case no ID and even nothing inside the 2 >< (although something is displayed)
I found an interesting solution here and tried to adapt it to my case:
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
But nothing appears in my textbox. Do someone have an idea? I think its because InnerText
refers to nothing in this case...
I hope I was clear enough.
Thanks a lot
Upvotes: 1
Views: 322
Reputation: 3800
Instead of d.GetAttribute("class") = "js-text-container"
use
d.GetAttribute("className") = "js-text-container"
I tested it locally, I believe you can use it in VB.Net
foreach (HtmlElement el in webBrowser1.Document.GetElementsByTagName("div"))
if (el.GetAttribute("className") == "js-text-container")
{
textBox1.Text = el.InnerText;
}
Hope it helps!
Upvotes: 2