未发现的Chromedriver如何使用用户名/密码添加代理?

发布于 2025-01-30 02:25:13 字数 803 浏览 8 评论 0 原文

我以这种方式添加Chrome选项,如果使用代理IP身份验证,它可以正常工作。

    options = webdriver.ChromeOptions() 
    options.headless = True
    options.add_argument('--proxy-server=92.128.165.143:3399')
    driver = uc.Chrome(options=options)

但是,我有一个以这种格式进行身份验证的代理: http://用户名:

如果我添加它

options.add_argument('--proxy-server=http://username:[email protected]:3399')

不起作用。如何使用用户名/密码添加它?这仅适用于未发现的铬驱动器。

I am adding chrome options this way and it works if I use proxy ip authentication.

    options = webdriver.ChromeOptions() 
    options.headless = True
    options.add_argument('--proxy-server=92.128.165.143:3399')
    driver = uc.Chrome(options=options)

However, I have a proxy with authentication in this format:
http://username:[email protected]:3399

If I add it like

options.add_argument('--proxy-server=http://username:[email protected]:3399')

it doesn't work. How could I add it with username/password? This applies only to undetected chrome driver.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

假装爱人 2025-02-06 02:25:13

不幸的是,目前只有一种方法可以通过未发现的ChromeDriver进行身份验证。

import undetected_chromedriver.v2 as uc
import pyautogui
import time

PROXY_HOST = "PROXY_IP"
PROXY_PORT = 6893
PROXY_USER = "user"
PROXY_PASSWORD = "password"

chrome_options = uc.ChromeOptions()
chrome_options.add_argument(f'--proxy-server={PROXY_HOST}:{PROXY_PORT}')

driver = uc.Chrome(options=chrome_options)
driver.get('https://bing.com')

time.sleep(1)
pyautogui.typewrite(PROXY_USER)
pyautogui.press('tab')
pyautogui.typewrite(PROXY_PASSWORD)
pyautogui.press('enter')

Unfortunately at the moment there is only one way to authenticate with an undetected chromedriver.

import undetected_chromedriver.v2 as uc
import pyautogui
import time

PROXY_HOST = "PROXY_IP"
PROXY_PORT = 6893
PROXY_USER = "user"
PROXY_PASSWORD = "password"

chrome_options = uc.ChromeOptions()
chrome_options.add_argument(f'--proxy-server={PROXY_HOST}:{PROXY_PORT}')

driver = uc.Chrome(options=chrome_options)
driver.get('https://bing.com')

time.sleep(1)
pyautogui.typewrite(PROXY_USER)
pyautogui.press('tab')
pyautogui.typewrite(PROXY_PASSWORD)
pyautogui.press('enter')
半步萧音过轻尘 2025-02-06 02:25:13

我认为香港专业教育学院已经在Selenium Wire的帮助下实现了它,但它与Kivy Gui无法使用,因此可以拼写,但是如果您想与Kivy一起使用,那么您肯定会出现错误

from ast import Try


from pathlib import Path
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.proxy import *
from seleniumwire import undetected_chromedriver as uc
from fake_useragent import UserAgent
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from pyclick import HumanClicker
import pyautogui
import time

clicked=False

hostname = "188.74.183.126"
port = "8395"
proxy_username = "wclmiemy"
proxy_password = "a9hoxl4phkzr"
chrome_options = {
    'proxy': {
        'http': f'http://{proxy_username}:{proxy_password}@{hostname}:{port}',
        'https': f'https://{proxy_username}:{proxy_password}@{hostname}:{port}',
        'no_proxy': 'localhost,127.0.0.1'
    }
}




def delete_cache(driver):
    driver.execute_script("window.open('')")  # Create a separate tab than the main one
    driver.switch_to.window(driver.window_handles[-1])  # Switch window to the second tab
    driver.get('chrome://settings/clearBrowserData')  # Open your chrome settings.
    pyautogui.click("clear_data.png")

if __name__ == '__main__':
    email = "[email protected]"
    password = "moqaddaszaheenzaheen"
    ua = UserAgent()
    userAgent = ua.random
    options = webdriver.ChromeOptions()
    
 
    options.add_argument(f'user-agent={userAgent}')
    # options.add_argument('--ignore-certificate-errors-spki-list')
    # # options.add_argument('--ignore-ssl-errors')
    options.add_argument("--disable-infobars")
    
    browser = uc.Chrome(
        driver_executable_path="chromedriver",
        seleniumwire_options=chrome_options,
        options=options,
        use_subprocess=True
    )
    browser.maximize_window()
    browser.get('https://www.youtube.com/watch?v=uPxkrGL0l7U')
    ```
this code is kind of messy but im in Hurry hope you will be able to modify you willa also get ssle that you need to import in chrome thats it you will defnitely get it

    

I think Ive achieved it already by the help of selenium wire but it didnt work with kivy gui so for scripting you can carryon like this but if you wanna use with kivy then definitely you will get error

from ast import Try


from pathlib import Path
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.proxy import *
from seleniumwire import undetected_chromedriver as uc
from fake_useragent import UserAgent
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from pyclick import HumanClicker
import pyautogui
import time

clicked=False

hostname = "188.74.183.126"
port = "8395"
proxy_username = "wclmiemy"
proxy_password = "a9hoxl4phkzr"
chrome_options = {
    'proxy': {
        'http': f'http://{proxy_username}:{proxy_password}@{hostname}:{port}',
        'https': f'https://{proxy_username}:{proxy_password}@{hostname}:{port}',
        'no_proxy': 'localhost,127.0.0.1'
    }
}




def delete_cache(driver):
    driver.execute_script("window.open('')")  # Create a separate tab than the main one
    driver.switch_to.window(driver.window_handles[-1])  # Switch window to the second tab
    driver.get('chrome://settings/clearBrowserData')  # Open your chrome settings.
    pyautogui.click("clear_data.png")

if __name__ == '__main__':
    email = "[email protected]"
    password = "moqaddaszaheenzaheen"
    ua = UserAgent()
    userAgent = ua.random
    options = webdriver.ChromeOptions()
    
 
    options.add_argument(f'user-agent={userAgent}')
    # options.add_argument('--ignore-certificate-errors-spki-list')
    # # options.add_argument('--ignore-ssl-errors')
    options.add_argument("--disable-infobars")
    
    browser = uc.Chrome(
        driver_executable_path="chromedriver",
        seleniumwire_options=chrome_options,
        options=options,
        use_subprocess=True
    )
    browser.maximize_window()
    browser.get('https://www.youtube.com/watch?v=uPxkrGL0l7U')
    ```
this code is kind of messy but im in Hurry hope you will be able to modify you willa also get ssle that you need to import in chrome thats it you will defnitely get it

    
呆° 2025-02-06 02:25:13

使用以下代码添加用户名和密码添加代理:

from selenium import webdriver

PROXY = "http://username:[email protected]:3399"

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

driver = webdriver.Chrome(chrome_options=chrome_options)

编辑:

我找到了此如何在硒中使用身份验证来设置代理?

Use the following code to add proxy with username and password:

from selenium import webdriver

PROXY = "http://username:[email protected]:3399"

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

driver = webdriver.Chrome(chrome_options=chrome_options)

edit:

I found this how to set proxy with authentication in selenium chromedriver python?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文