微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何从activex资源管理器中检索显示的文本?

如何解决如何从activex资源管理器中检索显示的文本?

;太长了,我认为没有必要在这文章显示
Gui Add,ActiveX,w400 h225 vWB,Shell.Explorer
URL := certain url
WB.Navigate(URL)
ComObjConnect( 
Gui Show,

我几乎不知道 com 并尝试通过网络搜索任何有用的信息。 据我所知,上面显示的资源管理器可以通过 com 控制。所以我试图找到一种方法来检索显示的文本,而不是里面的源代码。我想一定有办法,但对我来说很难。希望有人给我一个提示解决方案。

解决方法

在使用 Autohotkey 之前,我倾向于使用 PowerShell 来发现如何处理涉及 COM 对象的事情。

示例:

$ie = New-Object -ComObject InternetExplorer.Application
# Show the available members of the object
$ie | gm
$ie.Visible = $true
$ie.Navigate("www.google.com")
# This should show you all you can do on the document object
$ie.Document | gm

也就是说 GUI 中的 ActiveX 控件不是“InternetExplorer.Application”,所以它有点不同。您可以使用 https://adminscache.wordpress.com/2013/05/22/open-web-browser-in-powershell-gui/ 之类的内容打开相同的类型。

无论如何,这是一个工作示例,我花了很长时间!

; https://autohotkey.com/board/topic/93660-embedded-ie-shellexplorer-render-issues-fix-force-it-to-use-a-newer-render-engine/
FixIE(Version=0,ExeName="")
{
    static Key := "Software\Microsoft\Internet Explorer"
    . "\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION",Versions := {7:7000,8:8888,9:9999,10:10001,11:11001}
    
    if Versions.HasKey(Version)
        Version := Versions[Version]
    
    if !ExeName
    {
        if A_IsCompiled
            ExeName := A_ScriptName
        else
            SplitPath,A_AhkPath,ExeName
    }
    
    RegRead,PreviousValue,HKCU,%Key%,%ExeName%
    if (Version = "")
        RegDelete,%ExeName%
    else
        RegWrite,REG_DWORD,%ExeName%,%Version%
    return PreviousValue
}

FixIE()
Gui Add,ActiveX,w400 h225 vWB hwndTest,Shell.Explorer
URL := "https://en.wikipedia.org/wiki/AutoHotkey"
WB.Navigate(URL)
ComObjConnect(WB)
Gui Show,while,WB.ReadyState < 4
    Sleep,10

jtest := "var r = document.createRange();r.selectNode(document.body);window.getSelection().removeAllRanges();window.getSelection().addRange(r);document.body.setAttribute('ahk',window.getSelection().toString().trim());window.getSelection().removeAllRanges();"
WB.document.parentwindow.execScript(jtest)
MsgBox,% WB.document.body.getAttribute("ahk")
return


GuiClose:
ExitApp

参考:https://autohotkey.com/board/topic/93660-embedded-ie-shellexplorer-render-issues-fix-force-it-to-use-a-newer-render-engine/

关键是使用 JavaScript 来获取文本,获取特定元素的文本会更容易,只需使用 getElementById 或类似的东西。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。