Untitled

 avatar
unknown
plain_text
2 years ago
849 B
4
Indexable
const request = require('request');
const cheerio = require('cheerio');

// list of URLs to scrape
const urls = [
  'https://www.example.com/product1',
  'https://www.example.com/product2',
  'https://www.example.com/product3'
];

// function to scrape the price from a single URL
const scrapePrice = url => {
  // make a request to the URL
  request(url, (error, response, html) => {
    if (!error && response.statusCode == 200) {
      // load the HTML into cheerio
      const $ = cheerio.load(html);
      // find the element containing the price
      const priceEl = $('.price');
      // get the text content of the element
      const price = priceEl.text();
      // log the price
      console.log(price);
    }
  });
}

// iterate over the list of URLs
for (const url of urls) {
  // scrape the price from each URL
  scrapePrice(url);
}
Editor is loading...