【问题标题】:How to access Javascript array using COM with Autohotkey如何使用带有 Autohotkey 的 COM 访问 Javascript 数组
【发布时间】:2015-03-30 13:39:37
【问题描述】:

一段时间以来,我一直在使用 Autohotkey 来访问网页上的某些元素,我可以使用:wb.document.elements[x].forms[x].value 并将其分配给一个值。抱歉,我对 Javascript 的了解非常有限。

最近我查看了页面的代码并注意到以下内容:

<script type="text/javascript" defer="defer"> 
form = new ActiveForm('EditingServiceInformationforSOMEGUY','Editing Service Information for SOME GUY');
    data = {};
    data.header = ["addressid", "contactid", "address1", "address2", "city", "state", "zip"];
    data.body = [["275101010", "254101010", "1001 Maudlin", "Apt. 1774", "Beverly Hills", "CA", "90210"]];

我一直没有成功尝试通过 AHK 访问这个的 data.body 部分。如果我在查看页面时在地址栏中输入:

javascript: alert(data.body[0])

我得到一个消息框,其中 data.body 值以逗号分隔。

我似乎无法通过 Autohotkey 复制它。我尝试了很多不同的语法,但我在这里遗漏了一些东西。我想获得一个与我在 Javascript 警报中看到的值相同的 msgbox,然后从那里进一步操作它们。

我在脚本中尝试了许多不同的组合以将 data.body 显示为逗号分隔变量的列表,但似乎无法正确触发。

我当前的 AHK 代码如下,尝试分配 tempvar 的行是我无法正确处理的行。

Settitlematchmode, 2
WinGetTitle, Webstring, Title of the page
wb := IEGet(Webstring)

    tempvar := wb.document(data.header[0])
    msgbox % tempvar . "|" . Isobject(tempvar)
    IEGet(Name:="") {
        IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame
            Name := ( Name="New Tab - Windows Internet Explorer" ) ? "about:Tabs"
            : RegExReplace( Name, " - (Windows|Microsoft) Internet Explorer" )
        For wb in ComObjCreate( "Shell.Application" ).Windows
            If ( wb.LocationName = Name ) && InStr( wb.FullName, "iexplore.exe" )
                Return wb
    }

【问题讨论】:

标签: javascript autohotkey


【解决方案1】:

@vasili111 是在正确的轨道上。试试这个:

Settitlematchmode, 2
WinGetTitle, Webstring, Title of the page
wb := IEGet(Webstring)

IID := "{332C4427-26CB-11D0-B483-00C04FD90119}" ; IID_IHTMLWindow2
window := ComObj(9,ComObjQuery(wb,IID,IID),1)

    tempvar := window.data.header.0
    ; or use
    ;tempvar := window.eval("data.header[0]")

    msgbox % tempvar . "|" . Isobject(tempvar)
    IEGet(Name:="") {
        IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame
            Name := ( Name="New Tab - Windows Internet Explorer" ) ? "about:Tabs"
            : RegExReplace( Name, " - (Windows|Microsoft) Internet Explorer" )
        For wb in ComObjCreate( "Shell.Application" ).Windows
            If ( wb.LocationName = Name ) && InStr( wb.FullName, "iexplore.exe" )
                Return wb
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-28
    • 1970-01-01
    • 2023-02-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-18
    相关资源
    最近更新 更多