【问题标题】:HTA to get data from webpage to hta textboxHTA 从网页获取数据到 hta 文本框
【发布时间】:2018-12-28 09:38:35
【问题描述】:

使用 Hta 我想要从网页到 hta 文本框的数据。下面是我正在尝试创建的代码,但我不知道如何将数据从网页调用到 hta 文本框。

<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>

我需要的网页数据。

我在 hta 中需要的输出。

【问题讨论】:

标签: html web-scraping vbscript hta


【解决方案1】:

使用 window.ActiveXObject("Microsoft.XMLHTTP"),我们获取整个网页并将其分配给一个不可见/隐藏的 div(为简单起见)。请注意,由于网页自身的全局样式,这可能会导致不需要的样式。更好的方法是在单独的 IE 上打开网页。

HTA 默认引擎是 IE7,所以我们需要插入 meta http-equiv="x-ua-compatible" content="ie=9" 以支持 getElementsByClassName em> 功能,因为我们想从 99acres.com 获取的数据被 class 引用。

将下面的代码复制到记事本并保存为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>

【讨论】:

  • 嗨 Kennydelacruz 感谢您的回复,您真的是我的英雄,您的代码运行良好!!!!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多