Excel VBA Selenium打开本地网页运行时错误以及内存不足错误

我有一个本地.HTM文件的列表,我想用VBA (Excel 2013)中的Selenium进行parsing。 我遇到两个问题,但首先一些示例代码:

  Sub openSelenium() Dim html As HTMLDocument Dim selenium As SeleniumWrapper.WebDriver Set selenium = New SeleniumWrapper.WebDriver selenium.Start "firefox", "about:blank" selenium.Open "file:///D:/webpages/LE_1001.htm" Set html = selenium.getHtmlSource End Sub 

基本上我想要的是将每个本地网站的HTML Source Code存储在一个HTMLDocument元素中,这样我就可以使用HTMLDocument因为我熟悉它。 我在Windows 7 Pro SP1上使用FireFox v43.0.2和Excel 2013。

问题:上面的代码打开了FireFox,但是转到这个网页:“ https://www.mozilla.org/de/firefox/43.0.2/firstrun/learnmore/ ”并停在这里。

  1. VBA很快就会冻结,并收到以下消息: 在这里输入图像说明
  2. 我收到Excel Out of memory消息。 有时甚至在重新启动计算机之后仍收到此消息。 但这并不经常发生。 第一点更是一个问题。

任何帮助深表感谢。

您需要使用属于Firefox的默认configuration文件打开Firefox。 获取默认configuration文件并打开firefoxdriver。 这里是githuburl

  Class Script Dim driver Sub Class_Initialize Set driver = CreateObject("Selenium.FirefoxDriver") driver.SetProfile "default" 'Name of the profile driver.Get "https://mail.google.com/mail" End Sub Sub Class_Terminate driver.Quit End Sub End Class Set s = New Script 

如何检查configuration文件是否存在? 在Firefox?

https://support.mozilla.org/en-US/kb/profile-manager-create-and-remove-firefox-profiles

这个问题似乎是Mozilla Firefox的版本。 我使用的版本是43.0.2

降级到版本24.0后 ,代码似乎正常工作。 所以我认为这个问题最可能是FireFox的版本。

Selenium for VBA于2013年12月更新,因此安装了大约在同一时间发布的FireFox版本使其正常工作。

编辑:只要使用SeleniumBasic,你会避免所有这些问题。

去:

 C:\Users\your name\AppData\Local\SeleniumBasic\Scripts 

点击firefox并安装.net框架

去:

  control panel/turn on off windows feature and select `.net framework 3.5`