2

我正在尝试使用 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)

这个问题类似于这个问题但是,在那个问题中,他们的第一个请求是成功的。我没有成功。

什么会导致这种类型的异常但将消息留空?

4

1 回答 1

1

问题是我没有设置network.proxy.port. 添加这一行解决了这个问题:

profile.set_preference("network.proxy.port", "80")
于 2013-05-17T01:40:10.000 回答