python - 如何在 python 中为 chrome 的 webdriver 设置代理
问题描述
我已经尝试过:'''
from selenium import webdriver
PROXY = "23.23.23.23:3128" # IP:PORT or HOST:PORT
options = webdriver.ChromeOptions()
options.add_argument('--proxy-server=%s' % PROXY)
chrome = webdriver.Chrome('./chromedriver',options=options) #<----- I used './chromedriver' to set a PATH
chrome.get("http://whatismyipaddress.com")
''' 上面的代码取自how do i set proxy for chrome in python webdriver。
我从谷歌浏览器收到一个错误,说 ERR_NO_SUPPORTED_PROXIES,即使我使用的是公共的。
解决方案
你可以试试这个:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
PROXY = "23.23.23.23:3128" # IP:PORT or HOST:PORT
capabilities = dict(DesiredCapabilities.CHROME)
capabilities['proxy'] = {'proxyType': 'MANUAL','httpProxy': '23.23.23.23:3128','ftpProxy': '23.23.23.23:3128','sslProxy': '23.23.23.23:3128','noProxy': '','class': "org.openqa.selenium.Proxy",'autodetect': False}
chrome_options = Options()
chrome_options.add_argument("--disable-notifications")
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--verbose')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--disable-software-rasterizer')
chrome_options.add_argument('--headless')
chrome = webdriver.Chrome('./chromedriver',options=chrome_options) #<----- I used './chromedriver' to set a PATH
chrome.get("http://whatismyipaddress.com")
推荐阅读
- flutter - Flutter-关于在Cloud Firestore中创建聊天应用时的读取次数
- android - 如何将json对象解析为tablayout
- react-native - 世博+排毒+CircleCI
- html - 如何使用 Twig 获取 html 类名?
- android - Android Spinner 对ItemSelected 不起作用
- r - 如何将值分配给 is.na() 的输出?
- xamarin - 使用 Xamarin 时更改 Android 模拟器分辨率
- javascript - 将 ID 的值从部分视图传递到主视图
- python - 检查 4x4 网格是否有 2 个相邻的数字(向上或向下)等于某个数字
- javascript - 由于向上滚动图标,空白仅出现在移动视图中