可以使用HTA自动执行Web浏览吗? [英] Can HTAs be used to automate web browsing?

查看:123
本文介绍了可以使用HTA自动执行Web浏览吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是HTA的新手.我刚刚阅读了 https://msdn.microsoft .com/en-us/library/ms536496%28v = vs.85%29.aspx ,并且有点困惑.

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.

我可以使用HTA自动浏览吗?说我要下载网页并自动(即从脚本中)填写表格.如果有的话,HTA将如何帮助我做到这一点?重要的是下载的页面中的JavaScript代码应照常运行.完成初始化后,我应该能够以某种方式输入并填写表格,就像我是人工代理一样.

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.

推荐答案

首先,您需要打开IE窗口,如下所示:

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

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

然后将IE窗口导航到所需的网页:

Then navigate the IE window to the webpage you want:

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

您的IE窗口是可见还是不可见,取决于您.使用 Visible 属性使之可见:

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

IE.Visible = true;

然后,您应该等到网页完全加载后,再运行执行所需操作的功能.为此,首先,使用IE对象的 Document 属性从网页上获取HTML文档对象,然后重复检查文档对象的 readyState 属性.在下面的代码中,假定您有一个名为myFunc的函数,该函数在网页上执行所需的操作. (例如,修改网页的内容.)

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

在功能 myFunc 中,您可以对网页执行任何操作,因为HTML文档对象存储在 doc 变量中.您还可以使用 parentWindow 属性获取HTML窗口对象.

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.

这篇关于可以使用HTA自动执行Web浏览吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆