Skip to content

Instantly share code, notes, and snippets.

@G-Ray
Created May 18, 2015 21:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save G-Ray/b31d5f5950dac5e96613 to your computer and use it in GitHub Desktop.
Save G-Ray/b31d5f5950dac5e96613 to your computer and use it in GitHub Desktop.
cpasbien scraper
socket.on('msg', function(msg){
if(msg['cpb_request']) {
var url = msg['cpb_request']; //url de cpasbien avec recherche sur les films en x264
console.log(url);
request(url, function(error, response, html) {
var cheerio = require('cheerio');
var $ = cheerio.load(html);
var json = {"MoviesList": []}
var MovieList = [];
var order = [];
var movies = [];
var i = 0;
var j =0;
$('.ligne0 a, .ligne1 a').each(function(el, link) {
var title = $(link).text();
order.push(title);
j++;
request($(link).attr('href'), function(error, response, html) {
var movie = {"imdb":"", "title":"", "synopsis":"", "torrent_url":"", "poster":"", "description":""};
var html = cheerio.load(html);
var poster = html('#bigcover img').attr('src');
var torrent = html('#telecharger').attr('href');
movie.imdb = torrent.substring(torrent.lastIndexOf("/") + 1, torrent.length);
movie.imdb = movie.imdb.substring(0, movie.imdb.lastIndexOf("."));
var synopsis = html('#textefiche p').eq(1).text();
movie.synopsis = synopsis;
movie.description = synopsis;
movie.poster = poster;
movie.title = title;
movie.torrent_url = 'http://cpasbien.pe' + torrent;
movies.push(movie);
i++
//Replace movies in the correct order
if(i === j) {
for(var k=0; k<order.length; k++) {
for(var l=movies.length-1; l>=0; l--) {
if(movies[l].title === order[k]) {
MovieList.push(movies[l]);
movies.splice(l, 1);
}
}
}
var data = {"MovieList":MovieList};
socket.emit('cpb_request', data);
}
});
})
});
}
@mistertest
Copy link

G-ray je comprends pas où est déclarer l'url de recherche cpasbien "cpb_request" ??
Tu l'as déclaré dans un autre fichier ?? Je débute en même temps avec node et le scrapping.
Thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment