I am trying to extract some values using VBA from a Website
The following code contains the array of the data I am looking for. This works perfectly and gives me the array of the data I am looking for.
document.getElementsByClassName("list-flights")(0).querySelectorAll("[class$='price']")
The result for the above is
<NodeList length="23">...</NodeList>
But when I am trying to extract the values by running the loop in a VBA by using the following code
lnth = document.getElementsByClassName("list-flights")(0).querySelectorAll("[class$='price']").Length - 1
For x = 0 To lnth
firstResult = document.getElementsByClassName("list-flights")(0).querySelectorAll("[class$='price']")(x).innerText
Next x
The code would give error at firstResult since it would not get any value. I checked on Internet Explorer there is no value if I use "(" brackets,however if I use "[" on Internet Explorer it works but VBA would not accept "[" Brackets.
document.getElementsByClassName("list-flights")(0).querySelectorAll("[class$='price']")[0]
The code above works on Internet Explorer Console but cant be used in VBA.
I am sure I am missing something would be of great help if you can advice what is the workaround on this.
To get the innerText, you can use
getElementsByClassName
2 more times, one of them insidefor each .. next
loop since your values are inlist-flights -> price -> cash js_linkInsideCell
:Using
.querySelectorAll("[class$='price']")
works as well, but it crashes IE object after parsing. Try and see if it crashes:Some quick notes:
1-You can use this code to wait for IE object to load url:
2-Sometimes, even if IE object is ready, query results are not returned that fast. This means the elements you are looking for are not ready yet and do not exists so you get an error message:
To avoid this message my workaround is as follows:
I hope this helps.