반응형
출처 : www.youtube.com/watch?v=4q9CNtwdawA
스크래핑 대상 : www.imdb.com/title/tt0111161/?ref=nv_sr_1
The Shawshank Redemption (1994) - IMDb
Directed by Frank Darabont. With Tim Robbins, Morgan Freeman, Bob Gunton, William Sadler. Two imprisoned men bond over a number of years, finding solace and eventual redemption through acts of common decency.
www.imdb.com
타이틀
css
<h1 class="">The Shawshank Redemption <span id="titleYear">
(<a href="/year/1994/?ref_=tt_ov_inf">1994</a>)</span> </h1>
selector
#title-overview-widget > div.vital > div.title_block > div > div.titleBar > div.title_wrapper > h1
console 확인
document.querySelector('div[class="title_wrapper"] > h1').innerText
>>> The Shawshank Redemption (1994)
등급
css
<span itemprop="ratingValue">9.3</span>
selector
#title-overview-widget > div.vital > div.title_block > div > div.ratings_wrapper >
div.imdbRating > div.ratingValue > strong > span
console 확인
document.querySelector('span[itemprop="ratingValue"]').innerText
>>> 9.3
리뷰 카운트
css
<span class="small" itemprop="ratingCount">2,304,514</span>
selector
#title-overview-widget > div.vital > div.title_block > div > div.ratings_wrapper >
div.imdbRating > a > span
console 확인
document.querySelector('span[itemprop="ratingCount"]').innerText
>>> 2,304,514
전체 소스
const puppeteer = require("puppeteer");
(async () => {
let movieUrl = "https://www.imdb.com/title/tt0111161/?ref=nv_sr_1";
// 브라우저를 보기 원할때
// let browser = await puppeteer.launch({ headless: false });
let browser = await puppeteer.launch();
let page = await browser.newPage();
await page.goto(movieUrl, { waitUntil: "networkidle2" });
let data = await page.evaluate(() => {
let title = document.querySelector('div[class="title_wrapper"] > h1').innerText;
let rating = document.querySelector('span[itemprop="ratingValue"]').innerText;
let ratingCount = document.querySelector('span[itemprop="ratingCount"]').innerText;
return {
title,
rating,
ratingCount,
};
});
console.log(data);
await browser.close();
})();
반응형
'자바스크립트 > puppeteer, cheerio' 카테고리의 다른 글
* facebook 자동 로그인 + 좋아요 + 구독자 수 ( only puppeteer ) (0) | 2020.11.17 |
---|---|
* instagram 자동 로그인 + 좋아요 자동 클릭 (only puppeteer ) (0) | 2020.11.15 |
* puppeteer auto click : 퍼펫티어 자동 클릭 (0) | 2020.11.13 |