Python3,无法使用chromedriver设置socks代理(socks.py类型整数错误) [英] Python3, can't set socks proxy with chromedriver (socks.py type integer error)

查看:129
本文介绍了Python3,无法使用chromedriver设置socks代理(socks.py类型整数错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过带有 chromedriver 和 python3.5 的 localhost 使用 socks5 代理.但是,我收到以下错误:

I'm trying to use a socks5 proxy via localhost with chromedriver and python3.5. However, I get the following error:

loading
Traceback (most recent call last):
  File "test.py", line 16, in <module>
    browser = webdriver.Chrome(chrome_options=options)
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/chrome/webdriver.py", line 62, in __init__
    self.service.start()
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/service.py", line 97, in start
    if self.is_connectable():
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/service.py", line 113, in is_connectable
    return utils.is_connectable(self.port)
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/common/utils.py", line 106, in is_connectable
    socket_ = socket.create_connection((host, port), 1)
  File "/usr/lib/python3.5/socket.py", line 702, in create_connection
    sock.connect(sa)
  File "/usr/local/lib/python3.5/dist-packages/socks.py", line 766, in connect
    _BaseSocket.connect(self, proxy_addr)
TypeError: an integer is required (got type str)

这是我正在使用的代码.

Here's the code I'm using.

import time
from datetime import datetime
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

options = webdriver.ChromeOptions()
options.add_argument("--proxy-server=socks5://127.0.0.1:9000")

print("loading")
browser = webdriver.Chrome(chrome_options=options)
print("getting url")
browser.get("http://www.atagar.com/echo.php")

这是 webdriver.py 中的错误吗?它是如何解析选项并将它们发送到代理的?还是我在这里做错了什么?

Is this a bug in webdriver.py and how it parses the options and sends them to bind to the proxy? Or is there something I am doing wrong here?

推荐答案

遇到了类似的问题.这就是我最终让它工作的方式.

Had a similar problem. This is how i got it working eventually.

from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy, ProxyType

options = webdriver.ChromeOptions()

proxy = Proxy()
proxy.proxyType = ProxyType.MANUAL
proxy.autodetect = False
proxy.httpProxy = proxy.sslProxy = proxy.socksProxy = "127.0.0.1:9000"
options.Proxy = proxy
options.add_argument("ignore-certificate-errors")


driver = webdriver.Chrome('/Users/benjamin/Developer/chromedriver', 
                          chrome_options=options) 

这篇关于Python3,无法使用chromedriver设置socks代理(socks.py类型整数错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆