2

Web ページの単体テストに Selenium/BeautifulSoup を使用しようとしています。Google にアクセスできないというエラーが表示されます。

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 に答える