我正在尝试使用Selenium / BeautifulSoup对网页进行单元测试。我收到了一个错误,虽然我无法使用谷歌。
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,但是,在这个问题中,他们首次请求成功。我没有成功。
什么可能导致此类异常但将消息留空?
答案 0 :(得分:1)
问题在于我没有设置network.proxy.port
。添加此行解决了问题:
profile.set_preference("network.proxy.port", "80")