如何在Selenium 4.1中使用代理

huangapple go评论62阅读模式
英文:

how to use proxy in selenium 4.1

问题

我正在尝试创建一个自动化项目,该项目将使用代理在一个网站上注册。但我无法使其工作。

我已经尝试了使用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://{user}:{pwd}@{end}/",
        "http": "http://{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。

英文:

i am trying to make an automation project which will use proxy to register in a site. but i am unable to get it work.

I have tried selenium-wire for proxy authentication still it doesn't work

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)

it's showing my original ip.

答案1

得分: 0

你可以使用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)
英文:

You can use SeleniumBase to proxy to a site.

pip install seleniumbase, then run this with python after filling in the proxy details:

from seleniumbase import SB

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

huangapple
  • 本文由 发表于 2023年7月11日 00:19:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/76655600.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定