英文:
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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论