Selenium-保留firefox缓存和历史文件

Selenium-保留firefox缓存和历史文件,firefox,selenium,Firefox,Selenium,有没有办法在启动Firefox时禁用Selenium创建临时目录和配置文件 我完全理解Selenium做事情的原因。我只是在尝试使用它创建Firefox缓存和历史记录,以便进行计算机取证培训。为此,我建立了一个干净的虚拟机,它有一个原始的用户帐户。我现在可以运行一个带有selenium API的Python脚本来启动firefox,访问几个网页并关机 问题是,它没有留下任何东西。这当然是很好的,如果你使用硒在其原始目的,但它阻碍了我的工作删除一切 那么,有没有一种方法可以禁用临时配置文件创建,只

有没有办法在启动Firefox时禁用Selenium创建临时目录和配置文件

我完全理解Selenium做事情的原因。我只是在尝试使用它创建Firefox缓存和历史记录,以便进行计算机取证培训。为此,我建立了一个干净的虚拟机,它有一个原始的用户帐户。我现在可以运行一个带有selenium API的Python脚本来启动firefox,访问几个网页并关机

问题是,它没有留下任何东西。这当然是很好的,如果你使用硒在其原始目的,但它阻碍了我的工作删除一切

那么,有没有一种方法可以禁用临时配置文件创建,只启动Firefox,就像用户在没有Selenium的情况下运行Firefox一样

下午5时34分增补: Java API文档中提到了一个系统属性webdriver.eau_概要文件,它可以防止删除临时文件。我找到了问题的根源,但在Python WebDriver类中似乎没有出现:

def quit(self):
        """Quits the driver and close every associated window."""
        try:
            RemoteWebDriver.quit(self)
        except (http_client.BadStatusLine, socket.error):
            # Happens if Firefox shutsdown before we've read the response from
            # the socket.
            pass
        self.binary.kill()
        try:
            shutil.rmtree(self.profile.path)
            if self.profile.tempfolder is not None:
                shutil.rmtree(self.profile.tempfolder)
        except Exception as e:
            print(str(e))
def quit(self):
        """Quits the driver and close every associated window."""
        try:
            RemoteWebDriver.quit(self)
        except (http_client.BadStatusLine, socket.error):
            # Happens if Firefox shutsdown before we've read the response from
            # the socket.
            pass
        self.binary.kill()
        try:
            shutil.rmtree(self.profile.path)
            if self.profile.tempfolder is not None:
                shutil.rmtree(self.profile.tempfolder)
        except Exception as e:
            print(str(e))
退出时删除文件似乎是无条件的。我将通过注射来解决这个问题

return self.profile.path

就在self.binary.kill()之后。这可能会破坏所有的事情,这是一件可怕的事情,但它似乎做的正是我想要它做的。返回值告诉调用函数/tmp下临时目录的随机名称。不优雅,但似乎可以工作。

添加5:34PM:Java API文档提到了一个系统属性webdriver.eau_配置文件,该配置文件将阻止删除临时文件。我找到了问题的根源,但在Python WebDriver类中似乎没有出现:

def quit(self):
        """Quits the driver and close every associated window."""
        try:
            RemoteWebDriver.quit(self)
        except (http_client.BadStatusLine, socket.error):
            # Happens if Firefox shutsdown before we've read the response from
            # the socket.
            pass
        self.binary.kill()
        try:
            shutil.rmtree(self.profile.path)
            if self.profile.tempfolder is not None:
                shutil.rmtree(self.profile.tempfolder)
        except Exception as e:
            print(str(e))
def quit(self):
        """Quits the driver and close every associated window."""
        try:
            RemoteWebDriver.quit(self)
        except (http_client.BadStatusLine, socket.error):
            # Happens if Firefox shutsdown before we've read the response from
            # the socket.
            pass
        self.binary.kill()
        try:
            shutil.rmtree(self.profile.path)
            if self.profile.tempfolder is not None:
                shutil.rmtree(self.profile.tempfolder)
        except Exception as e:
            print(str(e))
退出时删除文件似乎是无条件的。我将通过注射来解决这个问题

return self.profile.path
在self.binary.kill()之后的/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py中。这可能会破坏所有的事情,这是一件可怕的事情,但它似乎做的正是我想要它做的。返回值告诉调用函数/tmp下临时目录的随机名称。不优雅,但在重新编译后看起来很有用


如果存在一个更优雅的解决方案,我很乐意将其标记为正确的解决方案

即使firefox在没有selenium的情况下正常启动,它也会使用现有的配置文件目录,或者创建一个()。但是当我正常启动它时,它会创建~/.cache/mozilla/firefox/xxxxx dir,xxxxx在.mozilla/firefox中是相同的。通过Selenium启动时,此目录不会显示。这是我的问题。缓存似乎已被禁用,或者它出现在临时位置并立即被删除。谢谢,现在更清楚了-您谈论的是缓存,而不是配置文件。明白了。是的,很抱歉搞混了。它似乎创建了同时包含配置文件和缓存信息的/tmp/.hexid…/dir,但一旦调用quit(),它就会被删除。如果我不退出firefox,缓存状态是不干净的,那里存储的东西很少。这正是我试图用selenium解决的问题:在firefox操作后完全关闭。只要我能阻止/tmp目录被删除,我就可以使用它。不是真的。请参阅我稍后的帖子。