簡體   English   中英

Python Selenium代理拋出異常

[英]Python Selenium proxy throws exception

我有一段非常簡單的代碼:

from selenium.webdriver.common import proxy as _px
myProxy = 'http://217.76.186.242:1080'

proxy = _px.Proxy({
    'proxyType': _px.ProxyType.MANUAL,
    'httpProxy': myProxy,
    'ftpProxy': myProxy,
    'sslProxy': myProxy,
    'noProxy': ''})

profile = webdriver.FirefoxProfile()
profile.set_preference("general.useragent.override", choice(user_agents))
driver = webdriver.Firefox(firefox_profile=profile, proxy=proxy)
dirver.get("http://www.google.ru")

但它不起作用。 它引發了一個異常:

Traceback (most recent call last):
  File "google_blog.py", line 30, in <module>
    'noProxy': ''})
  File "/home/********/.virtualenvs/helpers/local/lib/python2.7/site-packages/selenium/webdriver/common/proxy.py", line 66, in __init__
    self.proxy_type = ProxyType.load(raw['proxyType'])
  File "/home/********/.virtualenvs/helpers/local/lib/python2.7/site-packages/selenium/webdriver/common/proxy.py", line 39, in load
    raise Exception("No proxy type is found for %s" % (value))
  Exception: No proxy type is found for {'FF_VALUE': 1, 'STRING': 'MANUAL'}  

似乎一切都很好。 但不是。 任何提示?

我看到了問題,臨時解決方法是使用

'proxyType': 'MANUAL' 

代替

'proxyType': ProxyType.MANUAL

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM