Parsing HTML With VB DOTNET
I am trying to parse some data from a website to get specific items from their tables. I know that any tag with the bgcolor attribute set to #ffffff or #f4f4ff is where I want to
Solution 1:
Use the InnerHtml
property of the HtmlElement
object (curElement
) you have, like this:
For Each curElement As HtmlElement In theElementCollection
Dim controlValue As String = curElement.GetAttribute("bgcolor").ToString
MsgBox(controlValue)
If controlValue.Equals("#f4f4ff") Or controlValue.Equals("#ffffff") Then
Dim elementValue As String = curElement.InnerHtml
End If
Next
Read the documentation of HtmlElement.InnerHtml Property for more information.
UPDATE:
To get the second child of the <tr>
HTML element, use a combination of FirstChild
and then NextSibling
, like this:
For Each curElement As HtmlElement In theElementCollection
Dim controlValue As String = curElement.GetAttribute("bgcolor").ToString
MsgBox(controlValue)
If controlValue.Equals("#f4f4ff") Or controlValue.Equals("#ffffff") Then
Dim firstChildElement = curElement.FirstChild
Dim secondChildElement = firstChildElement.NextSibling
' secondChildElement should be the second <td>, now get the value of the inner HTML
Dim elementValue As String = secondChildElement.InnerHtml
End If
Next
Post a Comment for "Parsing HTML With VB DOTNET"