Can HTAs be used to automate web browsing?

梦想与她 提交于 2019-12-11 14:45:42

问题


I am new to HTAs. I just read https://msdn.microsoft.com/en-us/library/ms536496%28v=vs.85%29.aspx and am a bit confused.

Can I use HTAs to automate browsing? Say I want to download a web page and fill in a form automatically, i.e. from a script. How would an HTA help me do this, if at all? It's important that the JavaScript code in the downloaded page is run as usual. I should be able to enter somehow and fill in the form after it has finished initializing, just as if I were a human agent.


回答1:


First, you need to open an IE window, as follows:

var IE = new ActiveXObject("InternetExplorer.Application");

Then navigate the IE window to the webpage you want:

IE.Navigate("www.example.com");

Wether your IE window is visible or invisible, it's up to you. Use Visible property to make it visible:

IE.Visible = true;

Then, you should wait until the webpage is completely loaded and then run a function that takes your desired actions. To do so, first, get the HTML document object from the webpage using Document property of IE object, then repeatedly check the readyState property of document object. In the code below, it is assumed that you have a function named myFunc, which takes your desired actions on the webpage. (For example, modifying the contents of the webpage.)

var doc = IE.Document;
interval = setInterval(function() {
    try
    {
        if (doc.readyState == "complete")
        {
            myFunc();
            clearInterval(interval);
        }
    }
    catch (e) {}
}, 1000);

In the function myFunc, you can do anything you want with the webpage since you have HTML document object stored in doc variable. You can also use parentWindow property to get the HTML window object.



来源:https://stackoverflow.com/questions/46613170/can-htas-be-used-to-automate-web-browsing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!