我正在尝试使用 Selenium/BeautifulSoup 对网页进行单元测试。尽管我无法使用 Google,但我收到了一个错误。
selenium.common.exceptions.WebDriverException: 消息: ''
我正在使用 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但是,在那个问题中,他们有一个成功的第一个请求。我还没有成功。
什么会导致这种类型的异常但将消息留空?
请您参考如下方法:
问题是我没有设置network.proxy.port。添加此行解决了问题:
profile.set_preference("network.proxy.port", "80")
