Mat*_*t B 3 python proxy selenium-chromedriver
我正在尝试通过带有 chromedriver 和 python3.5 的本地主机使用socks5 代理。但是,我收到以下错误:
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)
Run Code Online (Sandbox Code Playgroud)
这是我正在使用的代码。
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")
Run Code Online (Sandbox Code Playgroud)
这是 webdriver.py 中的错误以及它如何解析选项并将它们发送到代理?或者我在这里做错了什么?
小智 5
有类似的问题。这就是我最终让它工作的方式。
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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6073 次 |
| 最近记录: |