11

我的 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

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

难道我做错了什么?Selenium 中是否存在错误?谢谢

4

1 回答 1

22

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

driver.close()

和:

driver.quit()

再见

于 2013-09-03T05:26:19.203 回答