Skip to content

Instantly share code, notes, and snippets.

@chrisle
Last active July 2, 2016 01:57
Show Gist options
  • Save chrisle/9d944c2da0e3f43940424f2c1f1eef6f to your computer and use it in GitHub Desktop.
Save chrisle/9d944c2da0e3f43940424f2c1f1eef6f to your computer and use it in GitHub Desktop.

Revisions

  1. chrisle revised this gist Jul 2, 2016. 1 changed file with 20 additions and 0 deletions.
    20 changes: 20 additions & 0 deletions scraper.js
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,26 @@
    * (Also see: https://github.com/lapwinglabs/x-ray)
    *
    * Run with: node scraper.js
    *
    * Result:
    *
    * [ { rankCurrent: '1',
    * rankLast: 'Last Week: 1',
    * title: 'One Dance',
    * artist: 'Drake Featuring WizKid & Kyla' },
    * { rankCurrent: '2',
    * rankLast: 'Last Week: 2',
    * title: 'Can\'t Stop The Feeling!',
    * artist: 'Justin Timberlake' },
    * { rankCurrent: '3',
    * rankLast: 'Last Week: 3',
    * title: 'Panda',
    * artist: 'Desiigner' },
    * { rankCurrent: '4',
    * rankLast: 'Last Week: 4',
    * title: 'Don\'t Let Me Down',
    * artist: 'The Chainsmokers Featuring Daya' },
    * ....
    */

    var Xray = require('x-ray');
  2. chrisle renamed this gist Jul 2, 2016. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. chrisle created this gist Jul 2, 2016.
    25 changes: 25 additions & 0 deletions billboard_scraper.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    /**
    * Install x-ray with: 'npm install x-ray'
    * (Also see: https://github.com/lapwinglabs/x-ray)
    *
    * Run with: node scraper.js
    */

    var Xray = require('x-ray');

    var scraper = Xray({
    filters: {
    trim: function (value) {
    return typeof value === 'string' ? value.replace(/\n/g, '').trim() : value
    }
    }
    });

    scraper('http://www.billboard.com/charts/hot-100', '.chart-row__main-display',
    [{
    rankCurrent: '.chart-row__current-week',
    rankLast: '.chart-row__last-week',
    title: '.chart-row__song | trim',
    artist: '.chart-row__artist | trim'
    }]
    )(console.log);