2015-12-24 22 views
1

我有一個本地.HTM文件的列表,我想在VBA(Excel 2013)中使用Selenium解析。我遇到兩個問題,但首先一些示例代碼:Excel VBA Selenium打開本地網頁運行時錯誤以及內存不足錯誤

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 

基本上我想要的是存儲每個地方網站,該網站是在HTMLDocument元素被解析,所以我可以用HTMLDocument工作,因爲我的HTML Source Code熟悉它。 我在Windows 7 Pro SP1上使用FireFox v43.0.2和Excel 2013。

問題:上面的代碼打開了FireFox,但是轉到這個網頁:「https://www.mozilla.org/de/firefox/43.0.2/firstrun/learnmore/」並停在這裏。

  1. 的VBA凍結不久,我收到以下消息: enter image description here
  2. 我收到Excel中Out of memory消息。有時我甚至在重新啓動計算機後收到此消息。但這種情況並不常見。第1點更是一個問題。

任何幫助,非常感謝。

回答

0

的問題似乎是Mozilla Firefox瀏覽器的版本。我正在使用版本43.0.2

降級到版本24.0後,代碼似乎正常工作。所以我認爲這個問題最可能是FireFox版本。

Selenium for VBA上次更新Dec. 2013,因此安裝FireFox version這是在大約同一時間發佈,使其正常工作。

編輯:只要使用SeleniumBasic,你將避免所有這些問題。

0

您需要使用屬於Firefox的默認配置文件打開Firefox。獲取默認配置文件並打開firefoxdriver。這裏是github URL

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 

如何檢查配置文件是否存在?在Firefox中?

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

+0

謝謝你的努力,但是這不是我一直在尋找。事實上,在我將Firefox降級到版本24,0後,問題就解決了,所以我猜想它與FireFox版本有關, – user3185735

0

轉到:

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

點擊Firefox和安裝.NET Framework

轉到:

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