2
我正在嘗試使用Selenium/BeautifulSoup來單元測試網頁。儘管我無法訪問Google,但我收到了一條錯誤消息。Selenium中的空錯誤消息WebDriverException
selenium.common.exceptions.WebDriverException: Message: ''
我使用Firefox和代理的一個便攜版本。
import urllib2
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
import time
import sys
def getItemDivs(url):
profile = webdriver.FirefoxProfile()
profile.set_preference("general.useragent.override","Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/21.0")
profile.set_preference("network.proxy.http", "proxy.example.com")
ffbin = webdriver.firefox.firefox_binary.FirefoxBinary('C:\\FirefoxPortable\\App\\Firefox\\firefox.exe')
# IT FAILS ON THE NEXT LINE
driver=webdriver.Firefox(profile, firefox_binary=ffbin)
driver.implicitly_wait(30)
# THIS LINE CONTAINS A VALID COOKIE, BUT IT HAS BEEN REMOVED FOR THIS QUESTION.
driver.add_cookie(<<mycookie>>)
base_url = url
verificationErrors = []
accept_next_alert = True
driver.get(base_url)
scrap1 = driver.page_source
soup = BeautifulSoup(scrap1)
這個問題類似於this one,然而,在這個問題他們有一個成功的第一個請求。我沒有成功。
什麼會導致這種類型的異常,但將消息留空?
感謝「ffbin = webdriver.firefox.firefox_binary.FirefoxBinary( 'C:\\ \\ FirefoxPortable應用\\ \\ Firefox的firefox.exe') #失敗在下一行 driver = webdriver.Firefox(profile,firefox_binary = ffbin)「 – nicky