-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (39 loc) · 1.6 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const axios = require('axios');
const cheerio = require('cheerio');
const json2csv = require('json2csv').Parser;
const fs = require('fs');
const url = 'https://www.imdb.com/'
axios.get('https://www.imdb.com/chart/top/?ref_=nv_mv_250')
.then((imdb) =>{
const $ = cheerio.load(imdb.data);
const movies = [];
const arrRating = [];
$('.titleColumn').each((index, element)=>{
/* console.log($(element).children().text()); */
const title = $(element).children().text();
const str1 = $(element).children('a').attr('href');
const link = url.concat(str1);
/* console.log(url.concat(str1)); */
movies[index] = {
Title: title,
Link: link,
};
})
$('.imdbRating').each((index, element)=>{
/* console.log($(element).children().text()); */
const rating = $(element).children().text();
movies[index].Rating = rating;
})
console.log(movies);
/* console.log(arrRating); */
/* const All = movies.concat(arrRating);
console.log(All); */
/* movies.push(arrRating) */
/* console.log($('.imdbRating').children().text()) */
const str1 = $('.titleColumn').children('a').attr('href');
/* console.log($('.lister-list').children().html());
console.log(url.concat(str1)); */
const jsonparser = new json2csv()
const csv = jsonparser.parse(movies)
fs.writeFileSync("./imdbmovies.csv", csv, "utf-8");
})