PhantomJS是否默认存储任何持久性文件? [英] Does PhantomJS store any persistent files by default?

查看:83
本文介绍了PhantomJS是否默认存储任何持久性文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为PhantomJS的新用户,我想确保我了解PhantomJS如何处理HTTP请求中累积的数据持久性.

As a new user to PhantomJS I want to be sure that I understand how PhantomJS handles any persistence of data that it accumulates from a HTTP request.

我的问题是:默认情况下PhantomJS是否持久存储任何数据(即,一个简单的示例,您没有在脚本中的任何地方使用require('fs')来存储请求,只是将其转储到STDOUT).我假设page.evaluate()调用中的所有工作都在内存中完成.

My question is: Does PhantomJS store any data persistently by default (i.e. a simple example where you are not using require('fs') anywhere in the script to store the request, just dumping it out to STDOUT). I am assuming that all of the work from a page.evaluate() call is done in memory.

这是一个简单的示例:

var page = require('webpage').create(),
system = require('system'),
address;

if(system.args.length != 2)
{
    console.log('Usage: phantomjs thisFile.js URL');
    phantom.exit(1);
}
else
{
    address = system.args[1];

    page.open(address, function (status)
    {
        if(status !== 'success')
        {
            console.log('Unable to load the address!');
            phantom.exit(1);
        }
        else
        {
            // Wait for the js to finish loading
            window.setTimeout(function(){
                var results = page.evaluate(function(){
                    return document.documentElement.innerHTML;
                });

                console.log(results); // This would be to stdout

                phantom.exit(0);
            }, 200);
        }
        console.log("Done.");
    });
}

该脚本将由phantomjs thisScript.js www.example.com之类的东西调用.

This script would be called by something like phantomjs thisScript.js www.example.com.

我知道您可以将页面保存到文件中,我只想确保我知道PhantomJS可以自行存储数据的所有地方.

I know that you can save a page to file, I just want to be sure that I am aware of all the places that PhantomJS may accumulate data on its own.

我还研究了 PhantomJS如何处理Cookie .

推荐答案

是的,默认情况下会保存一种类型,即localStorage数据库.

Yes, there is one type that is saved by default and this is the localStorage database.

  • 在Windows 7上:C:\Users\<user>\AppData\Local\Ofi Labs\PhantomJS
  • 在Windows 8上:C:\Ofi Labs\PhantomJs
  • 在Linux上:/home/<user>/.qws/share/data/Ofi Labs/PhantomJS
  • On Windows 7: C:\Users\<user>\AppData\Local\Ofi Labs\PhantomJS
  • On Windows 8: C:\Ofi Labs\PhantomJs
  • On Linux: /home/<user>/.qws/share/data/Ofi Labs/PhantomJS

仅当您添加命令行选项时,所有其他内容才会保存.磁盘缓存位于上述目录中,必须明确设置cookie文件路径.

Everything else is saved only when you add the commandline options. The disk cache is inside of the above directory and the cookie file path has to be set explicitly.

因此,这意味着如果您测试的Web应用程序不使用localStorage,则可以并行运行PhantomJS.

So it means that if the web application that you test doesn't use localStorage then you can run PhantomJS in parallel.

这篇关于PhantomJS是否默认存储任何持久性文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆