Last active
December 14, 2020 21:39
-
-
Save cristianbgp/6f6b7794c7041664a9c281653a66af61 to your computer and use it in GitHub Desktop.
Nvidia rtx scrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
const puppeteer = require("puppeteer"); | |
const links = [ | |
"https://www.sercoplus.com/video-nvidia-geforce-rtx/11817-vga-msi-geforce-nvidia-rtx-3060-ti-ventu.html", | |
"https://www.sercoplus.com/video-nvidia-geforce-gtx/11816-vga-msi-geforce-nvidia-rtx-3060-ti-gamin.html", | |
]; | |
(async () => { | |
const browser = await puppeteer.launch(); | |
const prices = ( | |
await Promise.allSettled( | |
links.map(async (link) => { | |
const page = await browser.newPage(); | |
await page.goto(link); | |
const [currentPrice] = await page.$$eval(".current-price", (elements) => | |
elements.map((element) => element.textContent) | |
); | |
const [name] = await page.$$eval(".page-heading", (elements) => | |
elements.map((element) => element.textContent) | |
); | |
const [description] = await page.$$eval( | |
".product-description-short", | |
(elements) => elements.map((element) => element.firstElementChild.textContent) | |
); | |
const [stock] = await page.$$eval( | |
".product-quantities", | |
(elements) => elements.map((element) => element.lastElementChild.dataset.stock) | |
); | |
return { name, currentPrice, description, stock: stock || 0 }; | |
}) | |
) | |
) | |
.filter((e) => e.status === "fulfilled") | |
.map((e) => e.value); | |
console.log(prices); | |
await browser.close(); | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "scrapping", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"bin": "./bin.js", | |
"author": "cristianbgp", | |
"license": "ISC", | |
"dependencies": { | |
"puppeteer": "^5.5.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment