Created
October 27, 2020 10:35
-
-
Save webhacking/8e1cd4d64be43f0701514a1753d324b7 to your computer and use it in GitHub Desktop.
for frd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios from 'axios'; | |
import cheerio from 'cheerio'; | |
import fs from 'fs'; | |
/** | |
* npm 은 package(=라이브러리) 매니저, 그래서 Node Package Manage 줄여서 npm | |
* npm 에서 라이브러리를 설치하려면, "npm install 라이브러리명" 을 입력하면 된다. | |
*/ | |
const getMovies = async (movieNumber) => { | |
const response = await axios.get(`https://movie.naver.com/movie/bi/mi/basic.nhn?code=${movieNumber}`); | |
const $ = cheerio.load(response.data); | |
/** | |
* 영화 이름 | |
* 영화 포스터 | |
* 영화 평점 | |
* 영화 출시년도 | |
* https://movie.naver.com/movie/bi/mi/basic.nhn?code=161967 | |
*/ | |
const name = $('.mv_info_area .mv_info h3.h_movie a:first-child').text(); | |
const created = $("#content > div.article > div.mv_info_area > div.mv_info > dl > dd:nth-child(2) > p > span:nth-child(4)").text().replace(/\s/g,'').replace(/개봉/g,'') | |
const scored = $("#pointNetizenPersentBasic").text(); | |
const country = $("#content > div.article > div.mv_info_area > div.mv_info > dl > dd:nth-child(2) > p > span:nth-child(2) > a").text(); | |
const type = $("#content > div.article > div.mv_info_area > div.mv_info > dl > dd:nth-child(2) > p > span:nth-child(1) > a").text() | |
if (!name) { | |
return; | |
} | |
console.log('name', name); | |
console.log('created', created); | |
console.log('scored', scored); | |
console.log('country', country); | |
console.log('type', type); | |
if (!fs.existsSync(`./movies`)) { | |
fs.mkdirSync('./movies'); | |
} | |
fs.writeFileSync(`./movies/${name}`, JSON.stringify({ | |
name, | |
created, | |
scored, | |
country, | |
type | |
})) | |
} | |
(async () => { | |
for (let i = 0; i < 999999; i++) { | |
await getMovies(i); | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment