从网站获取 data/text 到 HTA

Get data/text from website to HTA

我正在编写 HTA,我可以根据公司注册号从外部网站查找公司数据(公司名称、实体类型等)。

因为我在 HTA 中编程,所以我很难找到受支持的解决方案。我在 JavaScript、jQuery 和 VBScript 中尝试了不同的脚本,但 none 似乎在 HTA 中有效(有些在 JSFiddle 中有效,但在 HTA 中无效)。

我有以下 URL:https://datacvr.virk.dk/data/visenhed?enhedstype=virksomhed&id=24256790。 (注意 8 位代码,这是注册号)。

我想要以下文字:

Novo Nordisk A/S
Virksomhedsform: Aktieselskab

希望有人知道我如何获取请求的数据。

更新 #2:下面是我的完整 HTA 代码:

<html>
<HTA:APPLICATION ID="Company Data" APPLICATIONNAME="Company Data" BORDER="thick" CAPTION="yes" ICON=images\icon.ico MAXIMIZEBUTTON="yes" MINIMIZEBUTTON="yes" SHOWINTASKBAR="yes" SINGLEINSTANCE="no" SYSMENU="yes" RESIZE="yes" contextMenu=no></HTA:APPLICATION> 
<head>
<title>Regnskabskommetar</title>
<link href="include/stylesheet.css" rel="stylesheet" type="text/css" />
<link rel="SHORTCUT ICON" href="images/icon.ico"/>
<script type="text/javascript" charset="utf-8" src="include/jquery-1.7.min.js"></script>
<script type="text/javascript" charset="utf-8" src="include/underscore-min.js"></script>
<script type="text/javascript" charset="utf-8" src="include/autoNumeric-1.9.18.js"></script>
<script type="text/javascript" charset="utf-8" src="include/addFormat.js"></script>

<script>
function init()
{
var input = document.getElementById("cvr_nr").focus();
}
</script>

<script language="vbscript">
Set fso = CreateObject("Scripting.FileSystemObject")
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = false
ie.Navigate("https://datacvr.virk.dk/data/visenhed?enhedstype=virksomhed&id=24256790")

Dim dteWait 
dteWait = DateAdd("s", 1, Now())
Do Until (Now() > dteWait)
Loop

Set Table = ie.document.getElementsByClassName("table stamdata")
For x = 0 to (Table.length)-1
    Data = Data & Table(x).innerText
Next
ie.Quit()
MyFile = "DataLog.txt"
If fso.FileExists(MyFile) Then 
    fso.DeleteFile(MyFile)
End If

WriteTextFile Data, MyFile, -1
set ws = createObject("wscript.shell")
ws.run MyFile

Sub WriteTextFile(sContent, sPath, lFormat)
        ' lFormat -2 - System default, -1 - Unicode, 0 - ASCII
        With CreateObject("Scripting.FileSystemObject").OpenTextFile(sPath, 8, True, lFormat)
            .WriteLine sContent
            .Close
        End With
End Sub
</script>

<script type="text/javascript">
function reloadpage() {
    location.reload();
}
</script>

<script language="vbscript">
resizeto (screen.width)/2,(screen.height - 40) // 40 is the height of task bar
moveto (screen.width)/2,0
</script>

</head>
<body onLoad="init()" language="vbscript">

<table width="100%" border="0" cellpadding="0" cellspacing="0" style='margin-bottom: 5px;' id="sticky_navigation">
<tr>
<td height="40" id="top_bar" style="padding-left: 10px;">Company Data</td>
<td height="40" id="top_bar" align="right"><a href="include/Help.pdf" class="help">Help</a></td>
<td width="10" id="top_bar" align="right" style="padding-right: 10px;"><a href="#" tabindex="-1" onClick="reloadpage()"><img src="images/footer-logo.png" border="0" title="Opdatér" /></a></td>
</tr>
</table>

<table border="0" width="98%" cellpadding="0" cellspacing="0" style="margin-left: 10 px">
<tr>
<td width="40%">
<table border="0" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="110">
<b>CVR.</b><br>
<input name="cvr_nr" id="cvr_nr" title="CVR - Kan angives med og uden 00 foran" onchange="" style="text-align: left" size="12" type="number" required></td>
</td>
<td valign="top">
<b >Virksomhedsnavn</b><br>
<input style="text-align: left" value="Novo Nordisk A/S" size="50"></input>


<td valign="top">
<b>Virksomhedsform</b><br>
<input style="text-align: left" value="Aktieselskab" size="22" disabled></input>

</tr>
</table>

<div id="include_facility" class="switchcontent1"></div>

<br>
<table border="0" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td style="padding-top:5px">
<hr>
<button id="Scraper" onclick="Scraper()" name="Scraper" tabindex="1">Get company</button>
<hr>
</td
</tr>
</table>
<br>
<div id="content1"></div>

</body>
</html>

由于您没有提供任何代码,请尝试使用此 vbscript :

Set fso = CreateObject("Scripting.FileSystemObject")
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = false
ie.Navigate("https://datacvr.virk.dk/data/visenhed?enhedstype=virksomhed&id=24256790")
  Do until ie.ReadyState = 4
     WScript.Sleep 50
  Loop

Set Table = ie.document.getElementsByClassName("table stamdata")
For x = 0 to (Table.length)-1
    Data = Data & Table(x).innerText
Next
ie.Quit()
MyFile = "DataLog.txt"
If fso.FileExists(MyFile) Then 
    fso.DeleteFile(MyFile)
End If

WriteTextFile Data, MyFile, -1
set ws = createObject("wscript.shell")
ws.run MyFile

Sub WriteTextFile(sContent, sPath, lFormat)
        ' lFormat -2 - System default, -1 - Unicode, 0 - ASCII
        With CreateObject("Scripting.FileSystemObject").OpenTextFile(sPath, 8, True, lFormat)
            .WriteLine sContent
            .Close
        End With
End Sub