how to close Python selenium webdriver window

后端 未结 5 2007
南旧
南旧 2021-02-12 13:30

I have a python script that scraps data off from a website on an hourly basis. It is stored on the server at the moment and is working well as I am using task scheduler to sched

相关标签:
5条回答
  • 2021-02-12 14:10

    I think webDriver.Dispose() should work, It closes all browser windows. Here is a SO post about the 3 different ways to close a webdriver.

    0 讨论(0)
  • 2021-02-12 14:11

    For Python and chromedriver I've found these two methods useful (mind the difference):

    driver.close() - closes the browser active window.

    driver.quit() - closes all browser windows and ends driver's session/process.

    0 讨论(0)
  • 2021-02-12 14:12

    Could'nt you scrape in headless mode? (example for chrome)

    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument('--headless')
    chrome_options.headless = True
    ...
    driver = webdriver.Chrome(chrome_options=chrome_options)
    driver.create_options()
    
    0 讨论(0)
  • 2021-02-12 14:16

    I use linux command to close all. Here're two commands I ran after all scraping job is done:

    • pkill firefox
    • pkill Xcfb
    0 讨论(0)
  • 2021-02-12 14:18

    In python using chromedriver, I quit Chrome processes with:

    driver.close()
    
    0 讨论(0)
提交回复
热议问题