0

I'm programming a HTA where I can look up data on companies (company name, entity type etc.) from an external website, based on the company registration number.

Since I'm programming in a HTA I'm struggeling to find a solution that is supported. I have tried different scripts in JavaScript, jQuery and VBScript, but none seemed to work in the HTA (some worked in JSFiddle, but not in the HTA).

I have the following URL: https://datacvr.virk.dk/data/visenhed?enhedstype=virksomhed&id=24256790. (Note the 8 digit code which is the registration number).

I would like to have the following text:

Novo Nordisk A/S
Virksomhedsform: Aktieselskab

Hopefully someone knows how I can get the data which is requested.

Update #2: Below is my full HTA code:

<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>
Sparcx
  • 69
  • 12
  • 2
    Please share the code you tried and describe the issues. – omegastripes Oct 01 '17 at 20:09
  • 1
    "_Questions seeking debugging help ("why isn't this code working?") __must include__ the desired behavior, __a specific problem or error and the shortest code necessary to reproduce it in the question itself__. Questions without a clear problem statement are not useful to other readers. See: [mcve]._" – Teemu Oct 02 '17 at 03:58
  • 1
    Most likely you can't achieve this, HTA is not an exception what comes to [Same-origin policy](https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy), the same restrictions are applied. You need a server to access cross-origin pages. – Teemu Oct 02 '17 at 04:01
  • 1
    Check the answers: [this](https://stackoverflow.com/a/30856280/2165759), [this](https://stackoverflow.com/a/41538937/2165759), [this](https://stackoverflow.com/a/41528048/2165759), [this](https://stackoverflow.com/a/35782811/2165759). – omegastripes Oct 02 '17 at 20:11
  • Thank you @omegastripes for the links. I will try to adjust your scripts to see if I can get it to work in a HTA as well. – Sparcx Oct 04 '17 at 20:03
  • The autoNumeric version you are using is very, very old and not supported anymore. Please consider upgrading to either the jquery-dependent 1.9.46, or the latest no-dependency version `v4`. – Alex Oct 06 '17 at 06:40
  • @Alex, I appreciate your concern and you are of course right. In this case, however, the script is running on an internal computer, and the script must support HTA. Therefore: if it works, I'm not gonna fix it :-) – Sparcx Oct 07 '17 at 08:02

1 Answers1

2

Since you don't provide any code, give a try for this 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
Hackoo
  • 18,337
  • 3
  • 40
  • 70
  • I've managed to get the above script to work by replacing the WScript Sleep script as that did not work. `Dim dteWait dteWait = DateAdd("s", 1, Now()) Do Until (Now() > dteWait) Loop`. Now I just need to get the data from the .txt file sorted and printed in the HTA. – Sparcx Oct 04 '17 at 20:04
  • 1
    @Sparcx can you [edit](https://stackoverflow.com/posts/46515687/edit) your question and add the whole code of your modified HTA file ? – Hackoo Oct 04 '17 at 20:46