1
1
const xlsx = require ( 'xlsx' ) ;
2
2
const axios = require ( 'axios' ) ;
3
3
const cheerio = require ( 'cheerio' ) ;
4
+ const add_to_sheet = require ( './add_to_sheet' ) ;
4
5
5
6
const workbook = xlsx . readFile ( './data.xlsx' ) ;
6
7
8
+ console . log ( workbook . SheetNames ) ;
7
9
const ws = workbook . Sheets . 영화목록 ;
8
10
9
11
const records = xlsx . utils . sheet_to_json ( ws ) ;
@@ -13,16 +15,21 @@ for(const [i, r] of records.entries()) {
13
15
}
14
16
15
17
const crawler = async ( ) => {
18
+ add_to_sheet ( ws , 'C1' , 's' , '평점' ) ;
16
19
for ( const [ i , r ] of records . entries ( ) ) {
17
20
const response = await axios . get ( r . 링크 ) ;
18
21
if ( response . status === 200 ) {
19
22
const html = response . data ;
20
23
const $ = cheerio . load ( html ) ;
21
24
const text = $ ( '.score.score_left .star_score' ) . text ( ) ;
22
25
console . log ( r . 제목 , '평점' , text . trim ( ) ) ;
26
+ const newCell = 'C' + ( i + 2 ) ;
27
+ add_to_sheet ( ws , newCell , 'n' , parseFloat ( text . trim ( ) ) ) ;
23
28
}
24
29
}
30
+ xlsx . writeFile ( workbook , './result.xlsx' ) ;
25
31
} ;
32
+ //순서 보장
26
33
27
34
// const crawler = async () => {
28
35
// await Promise.all(records.map( async (r) => {
0 commit comments