Created
October 2, 2022 19:21
-
-
Save JWPapi/b3408709d8202dc3f5f2d379e1ffddb0 to your computer and use it in GitHub Desktop.
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
const lodash = require('lodash/util.js'); | |
const puppeteer = require('puppeteer-extra'); | |
const StealthPlugin = require('puppeteer-extra-plugin-stealth'); | |
puppeteer.use(StealthPlugin()); | |
const cheerio = require('cheerio'); | |
export default async function handler(req, res) { | |
console.time('handler'); | |
const {address, start, end} = req.query | |
const tokenIds = lodash.range(start, end); | |
const urls = tokenIds.map((tokenId) => `https://opensea.io/assets/matic/${address}/${tokenId}`); | |
const browser = await puppeteer.launch({headless: true}); | |
const promises = urls.map(async (url) => { | |
const page = await browser.newPage(); | |
page.goto(url, {waitUntil: 'domcontentloaded'}); | |
await page.waitForSelector(`[data-testid="ItemOwnerAccountLink"]`) | |
const html = await page.content(); | |
const $ = cheerio.load(html); | |
await page.close(); | |
return $(`[data-testid="ItemOwnerAccountLink"] a` ).attr('href').replace('/',''); | |
}) | |
const results = await Promise.all(promises); | |
await browser.close(); | |
console.timeEnd('handler'); | |
res.json({results}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment