Monday, 24 April 2017

How to scrape videos with node.js?

I'm trying to scrape & download clips from twitch.tv platform. It is a totally scrapable site.

Here's what I got so far:

var request = require('request'),
    cheerio = require('cheerio'),
    fs = require('fs');

var videos = [];

request('https://www.twitch.tv/directory/game/Counter-Strike:%20Global%20Offensive/clips', function(error, res, body) {
    if(!error && res.statusCode === 200) {
        var $ = cheerio.load(body);
        $('h3.cn-card__title a', 'div.tower tower--xs-1-1 tower--xxl-1-2 tower--gutter-none').each(function() {
            var video = $(this).attr('href');
            videos.push(video);

        });
        console.log(videos);
    }
});

The current problem is, I can't get any links from the web yet. I get empty array 'videos'.



via Petras Vilkelis

No comments:

Post a Comment