python-3.x 如何在Selenium 4.1中使用代理

djmepvbi  于 2023-11-20  发布在  Python
关注(0)|答案(2)|浏览(147)

我试图使一个自动化项目,将使用代理注册在一个网站。但我无法得到它的工作。
我已经尝试了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。

fiei3ece

fiei3ece1#

您可以使用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)

字符串

9o685dep

9o685dep2#

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

options.add_argument(f'--proxy-server={proxy["ip"]}:{proxy["port"]}')

字符串

相关问题