• Extract Data From Website Using VBS (vbscript)

    To get website data to using vbscript (.vbs) file, we need to know 2 processes. First one is to extract HTML code from website & then parse required data from HTML elements or tags.

    Objects Used: 

    • CreateObject(“MSXML2.XMLHTTP”) ‘ To sent xmlhttp request to webserver & get html code.
    • CreateObject(“htmlfile”) ‘ To parse data from html tags

    To parse data from html, we can use the below commands on a htmlfile object.

    • getElementById(“idname”)
    • getElementsByClassName(“classname”)
    • getElementsByTagName(“tagname – a,p,div,table,td,tr etc.,”)
    • DOMobject.getAttribute(“attributename – title, href,class,id etc.,”)
    • DOMobject.parentElement.NextSibling

    There are plenty of functions like this to traverse through each tags or elements in a valid html file. Now, lets see a working example. To test this code, replace the URL with a valid website address.


    To execute this code, copy paste this code to a text editor & save the file as “testing.vbs”. Then double click on this file, Windows OS will start to execute the commands one by one.

    Reference:


    Previous Post:
    Next Post: