【问题标题】:Close Python Selenium 's command line window after it runs using Window Batch使用 Window Batch 运行后关闭 Python Selenium 的命令行窗口
【发布时间】:2020-06-16 16:52:56
【问题描述】:

我使用 Python Selenium 进行网页抓取,使用批处理 .bat 文件触发它。 chrome浏览器和命令行窗口在运行成功后仍然打开。它应该被关闭,因为我将 exit 放在批处理脚本的末尾。见下面代码

timeout /t 2 /nobreak
"C:/Users/h/AppData/Local/Programs/Python/Python37/python.exe" "C:/Users/h/Desktop/Bbq/Python/Test.py"
timeout /t 12 /nobreak
exit

我在cmd中查看消息,这是截图

我想知道是否有任何错误导致了问题?请指教。

【问题讨论】:

  • 您对Exit 命令的作用有一个奇怪的期望,即:Quits the CMD.EXE program (command interpreter) or the current batch script.。它与您在批处理脚本或命令窗口中运行的任何程序无关。

标签: python selenium batch-file command-line


【解决方案1】:

使用此异常绕过所有错误,并强制浏览器退出

import traceback.

try:
    print(abcd)
except :
    print(traceback.format_exc())

    print("ERROR")
finally:
    driver.quit()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-28
    • 2013-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-24
    • 2012-08-29
    • 2018-03-01
    相关资源
    最近更新 更多