I want to use Excel VBA's internetexplorer.application to get values in a specific class in html in order

Asked 2 years ago, Updated 2 years ago, 54 views

For example, the following html is available:

To get the values (d, e, f) in span in the div of "class2" in order What should I do?

<div class="class1">
<span>a</span> 
<span>b</span>
<span>c</span>
</div>
<div class="class2">
<span>d</span>
<span>e>/span>
<span>f</span>
</div>

I came up with an idea and tried it as shown in the code below. If you can find the div object in class2
I understand that you will do the same for that object.
I got the values (a,b,c) and it didn't work.

For Eachobj1InobjIE.document.all.tags("div")
    Ifobj1.classname="class2" Then
        For Eachobj2Inobj1. document.all.tags("span")
            debug.print "span" & obj2.inertext & " - > " & obj2.inertext
        Next
    End If
Next

Thank you for your cooperation.

vba

2022-09-30 18:57

1 Answers

IE8 and later use the querySelectorAll method.

span

in "class2" div

div.class2span when expressed in the CSS selector.

For Each span InobjIE. document.querySelectorAll("div.class2span")
    debug.print "span" & span.inertext
Next

Is that so?


2022-09-30 18:57

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.