1

So due to constraints, I need to parse some ugly html with excel vba. the problem with the HTML is that it has no element IDs. I have a page that has many unlabeled tables that each have a couple rows. The only thing I can build from is that there is an identifier in one of the cells that I need to pull. Every time the ID "xtu_id" appears as a value in a cell in a row of a table, I want to pull the data from that row. So it looks like this:

<tr>



<td>

                    col1

</td>


<td>

                    col2

</td>


<td>

                    xtu_id

</td>


<td>

                    col4

</td>


</tr>  

Now that I see xtu_id exists in this row, I want to dump all cells of that row into an excel sheet. Here is what I used from reading other stackoverflow posts:

Sub CommandButton1_Click()

    Dim appIE As InternetExplorerMedium
    Set appIE = New InternetExplorerMedium

    With appIE
        .Navigate "https://my_website"
        .Visible = True
    End With

    Do While appIE.Busy Or appIE.ReadyState <> 4
        DoEvents
    Loop

    Set mydata = appIE.Document.getElementsByTagName("tr")

    For Each e In mydata
        For Each c In e
            If c.Cells().innerText Like "xtu_id" Then
                myValue = c.Cells().innerText
                MsgBox (myValue)
            End If
        Next c
    Next e
    Set appIE = Nothing

End Sub

This code works until I get to the [for each...] statement, I have trouble looping through each cell of each row to search for the "xtu_id" text. Any ideas on how to do this?

1 Answer 1

1

Try this:

For Each c In e.Cells
    If c.innerText Like "xtu_id" Then
        myValue = e.innerText
        MsgBox (myValue)
    End If
Next c
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the quick reply Scott, I swapped that in and did not get a value, but the code did not error out. perhaps my if statement isn't true
did you step through line-by-line and debug? An answer I provided earlier may help.
Thanks for the help Scott, so I swapped e.innertext for c.innertext to pull the cell values and got what I was after. Your answer was correct, it was my fault for not being clear what string I wanted to pull. Thanks again!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.