简体   繁体   English

在 selenium python 中使用代理

[英]Using proxies in selenium python

am trying to use selenium to change my IP using a code I found but am getting an error: selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH `from selenium import webdriver我正在尝试使用 selenium 使用我找到的代码更改我的 IP,但出现错误:selenium.common.exceptions.WebDriverException:消息:'chromedriver' 可执行文件需要在 PATH `from selenium import webdriver

PROXY = "23.23.23.23:3128" # IP:PORT or HOST:PORT PROXY = "23.23.23.23:3128" # IP:PORT 或 HOST:PORT

chrome_options = webdriver.ChromeOptions() chrome_options.add_argument('--proxy-server=http://%s' % PROXY) chrome_options = webdriver.ChromeOptions() chrome_options.add_argument('--proxy-server=http://%s' % PROXY)

chrome = webdriver.Chrome(chrome_options=chrome_options) chrome.get("http://whatismyipaddress.com")` chrome = webdriver.Chrome(chrome_options=chrome_options) chrome.get("http://whatismyipaddress.com")`

Here, I hope it helps :)在这里,我希望它有帮助:)

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

prox = Proxy()
prox.proxy_type = ProxyType.MANUAL
prox.http_proxy = "ip_addr:port"
prox.socks_proxy = "ip_addr:port"
prox.ssl_proxy = "ip_addr:port"

capabilities = webdriver.DesiredCapabilities.CHROME
prox.add_to_capabilities(capabilities)

driver = webdriver.Chrome(desired_capabilities=capabilities)

I solved this error by adding the executable path to the chrome variable我通过将可执行路径添加到 chrome 变量解决了这个错误

Here is my code :这是我的代码:

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

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server=ipaddress:port')
driver = webdriver.Chrome(executable_path="your executable path",chrome_options=chrome_options)
 driver.get('https://www.myip.com/')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM