Reputation: 109
I have this piece of code here, that's supposed to find an HTML element on this Reddit page and then return a value from it, and then store that in a zero-based 1d array. (I have an internet explorer instance called IE)
Dim awardelements As Object
Dim awards As String
awardelements = IE.document.querySelector("#siteTable > div")(0)
awards = awardelements.getAttribute("data-gildings")
results(i + 1, 14) = awards
So I'm trying to get the value of "data-gildings" (the # of awards the post got), but I'm getting an automation error on the awardelements = IE.document.querySelector("#siteTable > div")(0)
line. I'm not sure I can use the JS querySelector like that tbh so that might be the problem. I'd appreciate it if someone could point me in the right direction!
Thanks ^^
Upvotes: 2
Views: 123
Reputation: 84465
querySelector
returns a single node not a collection you can index into. And you need Set keyword as mentioned.
Dim awards As Object, awardCount As String
Set awards = ie.document.querySelector("#siteTable > div")
awardCount = awards.getAttribute("data-gildings")
Upvotes: 1