vba - 如何从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
解决方案
没有这样的事情Firefox.Application
。所以它永远不会起作用。
程序员使用 Internet Explorer - 可编程浏览器。所以使用Set site = CreateObject("InternetExplorer.Application")
AppActivate
使用 COM 时不需要它,它有大量规则阻止它为程序工作(它旨在防止程序窃取焦点)。
推荐阅读
- c - 为什么权限参数会影响我的小测试程序中写入文件的内容?
- json - Spark中Json列的哈希值
- react-native - 为什么 Android Emulator 只显示一个空白页面?
- sockets - 如何在程序集的套接字编程中找到参数的值?
- jquery - 视频标签有课时如何停止播放html 5视频?
- ios - 如何使 iPhone X 上的状态栏变为纯白色?
- java - 如何从json中获取列表列表?
- python - 使用 google 的 ip 而不是域名时的 TooManyRedirects
- c++ - 在 QObject 的方法中生成 QWidget
- laravel - 发生其他登录时如何向用户显示消息?