如何在selenium 4.1中使用代理

问题描述 投票:0回答:2

我正在尝试制作一个自动化项目,它将使用代理在网站中注册。但我无法让它工作。

我已经尝试使用 selenium-wire 进行代理身份验证,但仍然不起作用

from seleniumwire import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.options import Options
import os
import keyboard
import pyautogui
from time import sleep


user = 'jesbeqki'
pwd = '1wbt8dnqtu8w'
end = '2.56.119.93:5074'

seleniumwire_options ={
    "proxies" : {
    "https": "http://"f"{user}:{pwd}@{end}/",
    "http": "http://"f"{user}:{pwd}@{end}/",
    'verify_ssl': False
}
}
firefox_options = Options()
# firefox_options.add_argument("--headless")
driver = webdriver.Firefox(options=firefox_options, seleniumwire_options=seleniumwire_options)

driver.get('https://httpbin.org/ip')

text = driver.find_element(By.TAG_NAME, 'body').text
print(text)

它显示了我的原始IP。

python-3.x selenium-webdriver selenium-firefoxdriver
2个回答
1
投票

您可以使用 SeleniumBase 代理到站点。

pip install seleniumbase
,然后在填写代理详细信息后使用
python
运行:

from seleniumbase import SB

with SB(uc=True, proxy="USER:PASS@IP:PORT") as sb:
    sb.driver.get("https://whatismyip.com")
    sb.sleep(5)

0
投票

您可以尝试像这样添加代理配置:

options.add_argument(f'--proxy-server={proxy["ip"]}:{proxy["port"]}')
© www.soinside.com 2019 - 2024. All rights reserved.