我无法使用pjscrape输出到文件

时间:2014-09-06 22:37:12

标签: javascript web-scraping phantomjs

我正在尝试抓取整个页面并使用PJScrape将其保存到JSON文件中 运行以下代码,我可以在标准输出中看到整个DOM,但是我没有在当前目录中看到文件scrape_output.json

pjs.addSuite({
    // single URL or array
    url: 'http://en.wikipedia.org/wiki/List_of_towns_in_Vermont',
    // single function or array, evaluated in the client
    scraper: function() {
        return $(document).text();
    },

    // options: 'json' or 'csv'
    format: 'json',
    // options: 'stdout' or 'file' (set in config.outFile)
    writer: 'file',
    outFile: 'scrape_output.json'
});

1 个答案:

答案 0 :(得分:0)

我明白了。日志记录在pjs.config

中配置
pjs.addSuite({
    // single URL or array
    url: 'http://en.wikipedia.org/wiki/List_of_towns_in_Vermont',
    // single function or array, evaluated in the client
    scraper: function() {
        return $(document).text();
    }
});

pjs.config({
    // options: 'stdout', 'file' (set in config.logFile) or 'none'
    log: 'stdout',
    // options: 'json' or 'csv'
    format: 'json',
    // options: 'stdout' or 'file' (set in config.outFile)
    writer: 'file',
    outFile: 'scrape_output.json'
});
相关问题