VBA代码从Firefox获取数据并粘贴到Excel中 [英] vba code to get data from firefox and paste in excel

查看:249
本文介绍了VBA代码从Firefox获取数据并粘贴到Excel中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从网站上获取一些数据,我只能使用Firefox来访问该网站,我需要获取数据并将其粘贴到excel中,可以通过Internet Explorer进行处理,但是我无法进行排序用于Firefox.有人可以帮我吗?下面提到的网站是示例.原始网站是内部网络访问,网站将由表​​格中的数据组成. 预先感谢

i am trying to get some data from a website , i can only use Firefox to access the site and i need to get the data and paste it in excel , there are way to do it in internet explore but i cant sort out for Firefox. Can anyone help me with it ? below mentioned website is for sample .original website is internal network access, website will consist of data in a table. Thanks in advance

Sub Test_OpenFireFoxNewTab()
OpenInFireFoxNewTab "https://www.amazon.com"
End Sub

Sub OpenInFireFoxNewTab(url As String)
Dim pathFireFox As String
Dim ffDoc As Object
Dim ffApp As WebBrowser_V1
Dim ffTable As Object
Dim clip As DataTable
pathFireFox = "C:\Program Files (x86)\Mozilla Firefox\firefox.exe"
If Dir(pathFireFox) = "" Then pathFireFox = "C:\Program Files\Mozilla 
Firefox\firefox.exe"
If Dir(pathFireFox) = "" Then
MsgBox "FireFox Path Not Found", vbCritical, "Macro Ending"
Exit Sub
End If
Shell """" & pathFireFox & """" & " -new-tab " & url, vbHide

Set ffApp = New WebBrowser_V1

ffApp.Visible = True

Do While ffApp.Busy: DoEvents: Loop
Do Until ffApp.readyState = READYSTATE_COMPLETE: DoEvents: Loop
Set ffDoc = ffApp.document


ffApp.ExecWB OLECMDID_SELECTALL, OLECMDEXECOPT_DODEFAULT
ffApp.ExecWB OLECMDID_COPY, OLECMDEXECOPT_DODEFAULT

Sheets("Sheet2").Select
With ActiveSheet
LastCol = .Cells(3, .Columns.Count).End(xlToLeft).Column
End With
h = LastCol + 1
Cells(1, h).Select
ActiveSheet.PasteSpecial Format:="Unicode Text", link:=False, _
DisplayAsIcon:=False
Sheets("Sheet1").Select

ffApp.Quit
Set ffApp = Nothing
End Sub'

推荐答案

Windows计算机:

Windows machines:

从此处安装基本的硒.然后通过vbe>工具>引用添加对硒类型库的引用. FireFox驱动程序.exe必须位于 FF v.46.0.1 .

Install selenium basic from here. Then add a reference to selenium type library via vbe > tools > references. FireFox driver .exe must be in a folder that is on the environmental path or many users find putting it in the selenium folder works. I don't think you can use the latest FireFox versions. I think you need FF v.46.0.1.

Option Explicit
Public Sub ScrapeWithFireFox()
    Dim d As WebDriver
    Set d = New FirefoxDriver
    Const URL = "https://stackoverflow.com/"

    With d
         .get URL
        'do something with page
        Stop '<==Delete me later
        .Quit
    End With
End Sub

这篇关于VBA代码从Firefox获取数据并粘贴到Excel中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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