Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // import required libraries
- const axios = require('axios');
- const cheerio = require('cheerio');
- // define the URLs to scrape
- const urls = ['http://example.com/1', 'https://example.com/2', 'https://example.com/3']; // replace with actual URLs
- const scraper = async (urls) => {
- try {
- // loop through each URL
- for (let i = 0; i < urls.length; i++) {
- // make an HTTP GET request to the current URL
- const response = await axios.get(urls[i]);
- // load HTML content into Cheerio
- const $ = cheerio.load(response.data);
- // perform parsing operations
- // example:
- console.log(`Response for URL ${i + 1}:`, $('body').text());
- // wait for 5 seconds before making the next request
- await new Promise(resolve => setTimeout(resolve, 5000));
- }
- } catch (error) {
- console.error('Error:', error);
- }
- };
- scraper(urls);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement