'Read multiple web classes, add them to listview
Hey I have following problem I need to get specific values from website and more than one, here's an example of website code
<div class="content">
<div class="all-items">
<div class="item1">
<a href="link_to_Item" class="Itemname">Example Item</a>
</div>
<div class="itemsize">
" 103 "
<span> cm <span>
</div>
there more "item1" classes under the first with same name which I need to add in listview until there is no "item1" class more.
I tried following but its not throwing an error or anything...
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
For Each Element As HtmlElement In WebBrowser1.Document.GetElementsByTagName("div")
If Element.GetAttribute("className") = "content" Then
For Each Element0 As HtmlElement In WebBrowser1.Document.GetElementsByTagName("div")
If Element0.GetAttribute("className") = "all-items" Then
For Each Element1 As HtmlElement In Element.GetElementsByTagName("div")
If Element1.GetAttribute("className") = "item" Then
For Each Element2 As HtmlElement In Element.GetElementsByTagName("a")
If Element2.GetAttribute("className") = "href" Then
Dim vLink As String = Element2.InnerText
For Each Element3 As HtmlElement In Element.GetElementsByTagName("a")
If Element3.GetAttribute("className") = "Example Item" Then
Dim vTitle As String = Element3.InnerText
For Each Element4 As HtmlElement In Element.GetElementsByTagName("div")
If Element4.GetAttribute("className") = "itemsize" Then
Dim vSize As String = Element4.InnerText
For Each Element5 As HtmlElement In Element.GetElementsByTagName("span")
If Element5.GetAttribute("className") = "span" Then
Dim vUnit As String = Element5.InnerText
With lvList.Items.Add(vTitle)
.SubItems(0).Text = (vLink)
.SubItems(1).Text = (vSize + " " + vUnit)
End With
End If
Next
End If
Next
End If
Next
End If
Next
End If
Next
End If
Next
End If
Next
End Sub
its messy af but I should work theoretically except the size one and I'm not sure to if I get all "item1" classes with that I have literally no more idea at this point especially I failing to retrieve just one value.
any suggestions or help?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
