Search code examples
htmlweb-scrapingvbscripthta

HTA to get data from webpage to hta textbox


Using Hta i want data from web page to hta text Box. Below is the code which i am trying to create but i have no clue how to call data from web page to hta text box.

<html>
<head>
<title>My HTML Application</title>
<script language="vbscript">
  urls=("https://www.99acres.com/shri-laxmi-celebration-residency-sector-2b-vasundhara-ghaziabad-npxid-r63907?src=NPSRP&sid=UiB8IFFTIHwgUyB8IzEjICB8IG5vaWRhIzUjIHwgQ1AxMiB8IFkgIzE4I3wgIHwgMTIgfCMzIyAgfCA3ICM1I3wgIHwgMjMgfCM0MyMgIHw=")
    Sub RunLoop()
        window.navigate urls  
    End Sub
</script>
</head>
<body>
<input type="button" value="Click" onclick="RunLoop">
Possession:
<input type="text" name="Possession" Value="">
Configurations:
<input type="text" name="Configurations" Value="">
New Booking Base Price:
<input type="text" name="New Booking Base Price" Value="">
</body>
</html>

The data which i require from webpage.

enter image description here

The output which i require in hta.

enter image description here


Solution

  • Using window.ActiveXObject("Microsoft.XMLHTTP"), we get the whole webpage and assign it to an invisible/hidden div (for simplicity). Note that this may result to unwanted styling because of the webpage's own global styling. A better way to do it is to open the webpage on a separate IE.

    HTAs default engine is IE7 so we needed to insert meta http-equiv="x-ua-compatible" content="ie=9" in order to support the getElementsByClassName functionality because the data that we want to get from 99acres.com was referenced by class.

    Copy the code below to notepad and save it as xxx.hta:

    <html>
    <head>
    <meta http-equiv="x-ua-compatible" content="ie=9">
    <title>My HTML Application</title>
    <script language="javascript">
    
    var url= "https://www.99acres.com/shri-laxmi-celebration-residency-sector-2b-vasundhara-ghaziabad-npxid-r63907?src=NPSRP&sid=UiB8IFFTIHwgUyB8IzEjICB8IG5vaWRhIzUjIHwgQ1AxMiB8IFkgIzE4I3wgIHwgMTIgfCMzIyAgfCA3ICM1I3wgIHwgMjMgfCM0MyMgIHw=";
    var xmlHttp = new window.ActiveXObject("Microsoft.XMLHTTP");
    
    function httpGet(theUrl){
        xmlHttp.open( "GET", theUrl, false );
        xmlHttp.send( null );
        return xmlHttp.responseText;
    }
    
    function RunLoop() {
        var data = httpGet(url);
        document.getElementById("tempdiv").innerHTML = data;
        document.getElementsByName("Possession")[0].value = document.getElementsByClassName("factVal1")[0].innerHTML;
        document.getElementsByName("Configurations")[0].value = document.getElementsByClassName("factVal1")[1].innerHTML;
        document.getElementsByName("New Booking Base Price")[0].value = document.getElementsByClassName("factValsecond")[0].innerHTML;
    }
    
    </script>
    
    </head>
    <body>
    <input type="button" value="Click" onclick="javascript:RunLoop();">
    Possession:
    <input type="text" name="Possession" Value="">
    Configurations:
    <input type="text" name="Configurations" Value="">
    New Booking Base Price:
    <input type="text" name="New Booking Base Price" Value="">
    
    <div id="tempdiv" style="display:none;visibility:hidden;height:0px">
    </div>
    
    </body>
    </html>