Python Firefox Webdriver tmp文件

phc*_*aze 11 python tmp selenium-webdriver

我的python应用程序在几个小时的工作中使用Selenium Webdriver加载网页总共20000页.我的问题是"某些东西"正在创建大量的tmp文件,填满了我的所有硬盘.例如,今天早上应用程序在6小时的工作中生成70GB的tmp文件:(重启Ubuntu后,所有这些文件都消失了.我认为负责的是Firefox.

这种情况在Linux和OS X上都会发生.

def launchSelenium (url):
    profile = webdriver.FirefoxProfile()
    profile.set_preference("network.proxy.type", 1)
    profile.set_preference("network.proxy.http", "127.0.0.1")
    profile.set_preference("network.proxy.http_port", 8080)
    profile.set_preference("webdriver.load.strategy", "fast")
    profile.set_preference("permissions.default.stylesheet", 2)
    profile.set_preference("permissions.default.images", 2)
    profile.set_preference("dom.ipc.plugins.enabled.libflashplayer.so", "false")
    profile.set_preference("browser.sessionstore.enabled", "false")
    profile.set_preference("browser.cache.disk.enable", "false")
    profile.update_preferences()

    driver = webdriver.Firefox(firefox_profile=profile)

    driver.get(url)
    try:
        element = driver.find_element_by_xpath("//button[@title='Statistics']").click()
    except NoSuchElementException:
        print "Not available"
        driver.close()
        return 0
    driver.close()
    return 1
Run Code Online (Sandbox Code Playgroud)

我在Firefox Profile中添加了最后两个首选项,试图解决这个问题,但没有任何改变.

难道我做错了什么?Selenium有一个错误?谢谢

phc*_*aze 20

好的,问题的解决方案是替换:

driver.close()
Run Code Online (Sandbox Code Playgroud)

有:

driver.quit()
Run Code Online (Sandbox Code Playgroud)

再见