Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBScript GetElementsByClassName not supported?

Tags:

vba

vb6

vbscript

I am trying to convert some of my working VBA code to VBScript, but keep getting errors in VBScript when trying to use the getElementsByClassName method. Here's the full code:

option explicit

Dim XMLPage, html

Set XMLPage = WScript.CreateObject("MSXML2.XMLHTTP")
Set html= CreateObject("HTMLFile")

XMLPage.Open "GET", "https://www.hltv.org/stats/matches/mapstatsid/48745/immortals-vs-dignitas", False
Wscript.Sleep 50
XMLPage.send
Wscript.Sleep 50
If XMLPage.Status <> 200 Then MsgBox XMLPage.statusText

html.Open
html.write XMLPage.responseText
html.Close

'msgbox html.getElementsByTagName("tbody")(0).innertext'WORKS
msgbox html.getElementsByClassName("match-info-box-con")(0).innertext'DOESNT WORK

The last line of code is where the following error occurs: enter image description here

If I comment that out and run it to search for a tag name instead (code on the line above) - it works fine no problem.

I suspect it has something to do with how the variable html is declared, as from what I understand. getElementsByClassName comes from IHTMLElement6 - but I am unsure on how to get this to work in VBScript.

like image 388
Exam Orph Avatar asked Nov 18 '25 01:11

Exam Orph


1 Answers

MSHTML behaves differently depending on how it was instantiated - it exposes different interfaces depending on whether or not its early or late bound (its heavily reliant on IDispatch).

You are late binding and no interface exposing getElementsByClassName is available.

You can loop over document.all() and look at each item.className.

like image 77
Alex K. Avatar answered Nov 20 '25 18:11

Alex K.