【问题标题】:Saving Table from website results in more data then displayed on the page从网站保存表格会产生更多数据,然后显示在页面上
【发布时间】:2018-12-05 19:07:21
【问题描述】:

我对 nightmare.js 和 js 整体来说是新手,但我正在尝试从网站 Table View Source 保存一个表格,但它似乎也保存了可能用于其他设备的“灰色”数据(手机)什么的。有什么办法可以忽略这些或将设备设置为只看到设备的数据?

const Nightmare1 = require('nightmare');
var fs = require('fs');
var nightmare = Nightmare1({
show: true
});
const selector = 'table.table-striped:nth-child(1)';
nightmare
.goto(siteURL)
.evaluate(selector => {
    return document.querySelector(selector).outerHTML;
}, selector)
.then(function (page) {
    fs.writeFile('body.html', page, function (err) {
        if (err)
            return console.log(err);
        console.log('writing done');
    })
})
.catch(function () {
    console.log('caught', arguments);
});

【问题讨论】:

  • 脚本获得灰色项目是正常的,它们很可能只是在您的源视图浏览器中显示为灰色,以表明它们是使用 CSS 样式隐藏的。

标签: javascript web-scraping nightmare


【解决方案1】:

尝试排除包含您不想被您选择的课程的行 脚本。

因此,如果您不希望获取 visibility-tiny 类的行,请执行以下操作:

table.table-striped:nth-child(1):not(.visability-tiny)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-05
    • 1970-01-01
    • 2021-12-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多