web scraping in node js code example
Example 1: web scraping nodejs
const puppeteer = require('puppeteer')
const $ = require('cheerio')
(async () => {
const browser = await puppeteer.launch()
const page = await browser.newPage()
await page.goto('https://www.imdb.com/title/tt7126948/?ref_=nv_sr_srsg_0', { waitUntil: 'networkidle0' })
const content = await page.evaluate(() => document.body.innerHTML)
const data = $('div[class="title_wrapper"]', content).find('h1').text()
console.log(data)
await browser.close()
})()
Example 2: node.js web scraping
const request = require('request');
request('http://www.google.com', function (error, response, body) {
console.error('error:', error);
console.log('statusCode:', response && response.statusCode);
console.log('body:', body);
});