未检测到的Chromedriver未应用任何选项。

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

Undetected Chromedriver not applying any options

问题

未检测到的Chromedriver未应用我的选项。窗口大小未更改,扩展未加载。在Linux和Windows上都存在相同的问题。

from webdriver_manager.chrome import ChromeDriverManager
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
import undetected_chromedriver as uc

options = uc.ChromeOptions()
options.add_extension(proxies_extension)
options.add_argument("--window-size=500,500")

driver = uc.Chrome(service=Service(ChromeDriverManager().install()), options=options)

当我将上述代码替换为 options = webdriver.ChromeOptions()driver = webdriver.Chrome(... 时,它可以完美运行。

我可能做错了什么?提前感谢您的帮助。

英文:

Undetected Chromedriver is not applying my options. The windows size is not altered and the extension is not loaded. Same problem on Linux and Windows.

from webdriver_manager.chrome import ChromeDriverManager
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
import undetected_chromedriver as uc

options = uc.ChromeOptions()
options.add_extension(proxies_extension)
options.add_argument("--window-size=500,500")

driver = uc.Chrome(service=Service(ChromeDriverManager().install()), options=options)

It works perfectly when I substitute the above for options = webdriver.ChromeOptions() and driver = webdriver.Chrome(...

What could I possibly be doing wrong? Thanks in advance.

答案1

得分: 1

你可以使用SeleniumBase与Undetected Chromedriver上下文管理器格式,在浏览器启动后设置窗口大小:

首先安装pip install seleniumbase,然后使用python运行以下脚本:

from seleniumbase import DriverContext
import time

with DriverContext(uc=True, incognito=True) as driver:
    driver.get("https://nowsecure.nl/#relax")
    driver.set_window_size(500, 500)
    time.sleep(8)

还有另一种格式,不使用上下文管理器:

from seleniumbase import Driver
import time

driver = Driver(uc=True, incognito=True)
driver.get("https://nowsecure.nl/#relax")
driver.set_window_size(500, 500)
time.sleep(8)
driver.quit()
英文:

You can use SeleniumBase with the Undetected Chromedriver context manager format to set the window size after the browser spins up:

First pip install seleniumbase, and then run the following script with python:

from seleniumbase import DriverContext
import time

with DriverContext(uc=True, incognito=True) as driver:
    driver.get("https://nowsecure.nl/#relax")
    driver.set_window_size(500, 500)
    time.sleep(8)

And here's another format without the context manager:

from seleniumbase import Driver
import time

driver = Driver(uc=True, incognito=True)
driver.get("https://nowsecure.nl/#relax")
driver.set_window_size(500, 500)
time.sleep(8)
driver.quit()

huangapple
  • 本文由 发表于 2023年7月10日 10:55:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/76650424.html
匿名

发表评论

匿名网友

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

确定