首页 > 解决方案 > 如何从Firefox浏览器上打开的特定网页获取值

问题描述

我正在使用 AppActivate 来关注已在 Firefox 上打开的网页(不想打开新选项卡或其他 Firefox 实例)。从此选项卡中,我想通过复制特定值getElementById并粘贴到新工作表上以通过电子邮件发送。有人可以帮忙吗?我尝试了不同的方法,但直到现在都没有奏效。

Sub startFirefox()
    Dim appfile As String
    Dim fftask As Double

    appfile = "Firefox"
    On Error Resume Next
    AppActivate "Firefox"
        If Err <> 0 Then
            Err = 0
            fftask = Shell(appfile, 1)
            If Err <> 0 Then MsgBox "Cannot start FF" 'if firefox is not open going to open a new instance
        End If

    '2nd part that i need to get the values from web page
    Dim varA, Url As String
    Url = "example"
    Dim Site As Object
    Set Site = CreateObject("firefox.application")

    Dim oHTMLDoc As Object
    Set oHTMLDoc = Site.Document
    varA = oHTMLDoc.getElementById("X5").Value

    MsgBox varA  'here is not showing any value. I put the msgbox just to see if is getting any value
End Sub

标签: vba

解决方案


没有这样的事情Firefox.Application。所以它永远不会起作用。

程序员使用 Internet Explorer - 可编程浏览器。所以使用Set site = CreateObject("InternetExplorer.Application")

AppActivate使用 COM 时不需要它,它有大量规则阻止它为程序工作(它旨在防止程序窃取焦点)。


推荐阅读