cheerio-select-attribute

0.2.0 • Public • Published

cheerio-select-attribute

See package.json for description.

Implementation

See index.js

module.exports = ($, selector, attribute) => {
    const array = [];
    $(selector).each(function (index, element) {
        array.push($(element).attr(attribute));
    });
    return array;
};

Test

See test.js

const cheerio = require('cheerio');
 
async function main() {
    const $ = cheerio.load([
        `<time itemprop="openingHours" datetime="Mo 09:00-20:00">`,
        `<time itemprop="openingHours" datetime="Tu 09:00-20:00">`,
    ].join('\n'));
    const openingHours = selectAttribute($, 'time[itemprop=openingHours]', 'datetime');
    assert.equal(openingHours[0], 'Mo 09:00-20:00');
}

https://dotter.me/

Readme

Keywords

none

Package Sidebar

Install

npm i cheerio-select-attribute

Weekly Downloads

1

Version

0.2.0

License

private

Last publish

Collaborators

  • evanx