Skip to content Skip to sidebar Skip to footer

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:

ForEach curElement As HtmlElement In theElementCollection
    Dim controlValue AsString = curElement.GetAttribute("bgcolor").ToString
    MsgBox(controlValue)
    If controlValue.Equals("#f4f4ff") Or controlValue.Equals("#ffffff") ThenDim elementValue AsString = curElement.InnerHtml
    EndIfNext

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:

ForEach curElement As HtmlElement In theElementCollection
    Dim controlValue AsString = curElement.GetAttribute("bgcolor").ToString
    MsgBox(controlValue)
    If controlValue.Equals("#f4f4ff") Or controlValue.Equals("#ffffff") ThenDim firstChildElement = curElement.FirstChild
        Dim secondChildElement = firstChildElement.NextSibling

        ' secondChildElement should be the second <td>, now get the value of the inner HTMLDim elementValue AsString = secondChildElement.InnerHtml
    EndIfNext

Post a Comment for "Parsing Html With Vb Dotnet"