python - Selenium Chrome Webdriver 无法在带有配置文件的 headless 模式下工作

标签 python selenium selenium-chromedriver remote-debugging google-chrome-headless

所以,这是我遇到麻烦的代码:

def scrap():
        options = webdriver.ChromeOptions();
        options.add_argument('headless');
        options.add_argument('--profile-directory=Profile 1')
        options.add_argument("--user-data-dir=C:/Users/omarl/AppData/Local/Google/Chrome/User Data/")
        options.add_argument("--remote-debugging-port=45447")
    
        options.add_argument("--disable-gpu") 
        browser = webdriver.Chrome(executable_path=r"C:\Users\omarl\OneDrive\Escritorio\chromedriver.exe", options=options)
        
        scrapURL = "https://es.wallapop.com/search?distance=30000&keywords=leggins&latitude=41.38804&longitude=2.17001&filters_source=quick_filters"
        browser.get(scrapURL)
        #...
和错误:
WebDriverException: unknown error: unable to discover open pages
我没有任何 的实例 Chrome 当我执行脚本时,以及在没有 headless 的情况下使用它时选项它工作正常。知道为什么会这样吗?请注意,我使用的是 --remote-debuggin-port在类似的问题中提供。
我正在使用 ChromeDriver 86.0.4240.22

最佳答案

您是否尝试过使用 arg --no-sandbox?
很多人在Chrome Driver Error using Selenium: Unable to Discover Open Pages在这个论点上取得了成功。

关于python - Selenium Chrome Webdriver 无法在带有配置文件的 headless 模式下工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64771276/

相关文章:

c# - 如何在 C# Selenium 中获取表数据并将其保存在任何文档中

java - Selenium webdriver 等待,元素不可点击异常

java - 无法解决 selenium 驱动程序的导入问题

google-chrome - Google Chrome 29.0无法与Webdriver一起使用

python - 将 pandas.DataFrame 列的字符串值拆分为数组

python - 打印机模拟python程序中waittime是怎么计算的?

java - Selenium 在 Firefox 和 chrome 上的点击位置

python - django 2外键从一个模型到另一个模型

python - 递归字典创建python

google-chrome - Selenium WebDriverException : unknown error: call function result missing 'value' while calling sendkeys method