Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mkdir scraper
- cd scraper
- npm i puppeteer --save
- ######SCRIPT######
- const puppeteer = require('puppeteer');
- const url = process.argv[2];
- if (!url) {
- throw "Please provide URL as a first argument";
- }
- function run () {
- return new Promise(async (resolve, reject) => {
- try {
- const browser = await puppeteer.launch({headless: 'new'});
- const page = await browser.newPage();
- await page.goto(url);
- let urls = await page.evaluate(() => {
- let results = [];
- let items = document.querySelectorAll('a');
- items.forEach((item) => {
- results.push({
- url: item.getAttribute('href'),
- text: item.innerText,
- });
- });
- return results;
- })
- browser.close();
- return resolve(urls);
- } catch (e) {
- return reject(e);
- }
- })
- }
- run().then(console.log).catch(console.error);
- ########RUN#########
- node scrape.js "https://filmsbykris.com"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement