首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法写入CSV文件

无法写入CSV文件
EN

Stack Overflow用户
提问于 2017-04-10 20:07:50
回答 1查看 68关注 0票数 0

我只想使用JavaScript将抓取的urls存储在数组中。下面是我的代码:

代码语言:javascript
复制
var AxeBuilder = require('axe-webdriverjs');
var WebDriver = require('selenium-webdriver');
var json2csv = require('json2csv');
var fs = require('fs');
var crawled='';

var driver = new WebDriver.Builder()
  .forBrowser('firefox')
  .build();

driver
  .get('https://www.ally.com')
  .then(function () {
    AxeBuilder(driver)
      .analyze(function (results) {
        console.log(results.violations);
      });
  });

  const CrawlKit = require('crawlkit');
const AxeRunner = require('crawlkit-runner-axe');

const crawler = new CrawlKit('https://www.ally.com');
// You could add a finder here in order to audit a whole network of pages
crawler.addRunner('aXe', new AxeRunner());

crawler.crawl()
    .then((data) => {
        {
        console.log(JSON.stringify(data.results, true, 2));
        console.log(data.results.length);
    } (err) => console.error(err)



    var crawled = [];
          for (var i = 0; i < data.results.length; i++)
           {
            crawled.push({

              'url': data.results[i]

            });
          }

          });
    //storeCSV(crawled);
console.log(crawled);
var csv = json2csv({ data: crawled, fields: ['url'] });
storeCSV(csv);


function storeCSV(storeJSArray) {

  fs.writeFile('C:/Users/AppData/Roaming/npm/node_modules/crawl.csv', storeJSArray, function(err) {
    if (err) throw err;
    console.log('File saved!');
  });
}

预期结果:作为CSV文件

代码语言:javascript
复制
[ { description: 'Ensures the contrast between foreground and background colors
meets WCAG 2 AA contrast ratio thresholds',
    help: 'Elements must have sufficient color contrast',
    helpUrl: 'https://dequeuniversity.com/rules/axe/2.1/color-contrast?applicati
on=webdriverjs',
    id: 'color-contrast',
    impact: 'critical',
    nodes: [ [Object], [Object], [Object], [Object], [Object], [Object] ],
    tags: [ 'wcag2aa', 'wcag143' ] },
  { description: 'Ensures every id attribute value is unique',
    help: 'id attribute value must be unique',
    helpUrl: 'https://dequeuniversity.com/rules/axe/2.1/duplicate-id?application
=webdriverjs',
    id: 'duplicate-id',
    impact: 'critical',
    nodes: [ [Object], [Object], [Object] ],
    tags: [ 'wcag2a', 'wcag411' ] },
  { description: 'Ensures <iframe> and <frame> elements contain a non-empty titl
e attribute',
    help: 'Frames must have title attribute',
    helpUrl: 'https://dequeuniversity.com/rules/axe/2.1/frame-title?application=
webdriverjs',
    id: 'frame-title',
    impact: 'critical',
    nodes: [ [Object] ],
    tags: [ 'wcag2a', 'wcag241', 'section508', 'section508.22.i' ] },
  { description: 'Ensures every HTML document has a lang attribute',
    help: '<html> element must have a lang attribute',
    helpUrl: 'https://dequeuniversity.com/rules/axe/2.1/html-has-lang?applicatio
n=webdriverjs',
    id: 'html-has-lang',
    impact: 'serious',
    nodes: [ [Object] ],
    tags: [ 'wcag2a', 'wcag311' ] },
  { description: 'Ensures tabindex attribute values are not greater than 0',
    help: 'Elements should not have tabindex greater than zero',
    helpUrl: 'https://dequeuniversity.com/rules/axe/2.1/tabindex?application=web
driverjs',
    id: 'tabindex',
    impact: 'serious',
    nodes: [ [Object], [Object] ],
    tags: [ 'best-practice' ] } ]

实际行为:

代码语言:javascript
复制
'Url"

这是一个包含字段名的空白CSV文件。它尚未捕获已爬网的结果。我是不是错过了什么。任何关于这方面的建议都会很有帮助。

EN

回答 1

Stack Overflow用户

发布于 2017-04-10 20:12:25

您的数据中没有'url‘字段。你的意思是'helpURL‘吗?

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43322756

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档