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