【问题标题】:Selenium : How to Keep Browser open after code endsSelenium:如何在代码结束后保持浏览器打开
【发布时间】:2023-02-05 22:07:46
【问题描述】:

我正在执行自动化任务以单击某些网页。 我想要的是在完成编码工作后使用 chrome 浏览器。我已经通过 time.sleep() 做到了这一点,但我认为还有其他方法可以做到这一点......有什么好主意吗?

import datetime
import time
from selenium import webdriver
from selenium.webdriver.common.alert import Alert
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

options = webdriver.ChromeOptions()
options.add_argument("disable-gpu")
options.add_argument(
    "user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36")
options.add_argument("disable-infobars")
options.add_argument("--disable-extensions")
options.add_experimental_option("excludeSwitches", ["enable-logging"])
options.add_experimental_option("detach", True)
options.add_experimental_option("excludeSwitches", ["enable-automation"])

***automation code***

time.sleep(999999)

【问题讨论】:

  • 1) 为什么需要options.add_argument("disable-gpu")options.add_argument("disable-infobars")options.add_argument("--disable-extensions")? 2) options.add_experimental_option("detach", True) 不适合你吗?

标签: selenium selenium-webdriver selenium-chromedriver


【解决方案1】:

当您不使用driver.close()driver.quit() 时,它会一直打开直到您手动退出。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-24
    • 1970-01-01
    • 2011-08-21
    • 2019-04-12
    • 2019-09-16
    • 1970-01-01
    • 2011-11-25
    • 1970-01-01
    相关资源
    最近更新 更多