Opensea Scraper
🎉 UPDATE 2021-Nov-3: Opensea officially updated their API. You can get accurate realtime floor prices from this endpoint: https://api.opensea.io/api/v1/collection/{slug}/stats
:
const axios = require("axios");
async function getFloorPrice(slug) {
try {
const url = `https://api.opensea.io/collection/${slug}/stats`;
const response = await axios.get(url);
return response.data.stats.floor_price;
} catch (err) {
console.log(err);
return undefined;
}
}
await getFloorPrice("lostpoets");
await getFloorPrice("treeverse");
await getFloorPrice("cool-cats-nft");
If you need floor prices, please use the official API (see above 👆👆👆). This scraper still can be used to scrape additional information about offers (tokenId, name, tokenContractAddress and offerUrl) as well as the ranking.
Install
npm install opensea-scraper
Usage
ℹ slug
is the human readable identifier that opensea uses to identify a collection. It can be extracted from the URL: https://opensea.io/collection/{slug}
ℹ options
is an object with the following keys
debug
[Boolean] launches chromium locally, omits headless mode (default: false
)logs
[Boolean]: display logs in the console (default: false
)sort
[Boolean]: sorts the offers by lowest to highest (default: true
)browserInstance
[PuppeteerBrowser]: bring your own browser instance for more control
const OpenseaScraper = require("opensea-scraper");
const slug = "cool-cats-nft";
const options = {
debug: false,
logs: false,
sort: true,
browserInstance: undefined,
}
const basicInfo = await OpenseaScraper.basicInfo(slug);
let result = await OpenseaScraper.offers(slug, options);
console.dir(result, {depth: null});
let url = "https://opensea.io/collection/sandbox?search[sortAscending]=true&search[sortBy]=PRICE&search[stringTraits][0][name]=Type&search[stringTraits][0][values][0]=Land&search[toggles][0]=BUY_NOW";
result = await OpenseaScraper.offersByUrl(url, options);
console.dir(result, {depth: null});
let resultSize = 40;
result = await OpenseaScraper.offersByScrolling(slug, resultSize, options);
console.dir(result, {depth: null});
url = "https://opensea.io/collection/sandbox?search[sortAscending]=true&search[sortBy]=PRICE&search[stringTraits][0][name]=Type&search[stringTraits][0][values][0]=Land&search[toggles][0]=BUY_NOW";
resultSize = 40;
result = await OpenseaScraper.offersByScrollingByUrl(url, resultSize, options);
console.dir(result, {depth: null});
const type = "24h";
const ranking = await OpenseaScraper.rankings(type, options);
Debugging
To investigate an issue turn on logs and debug mode (debug: true
and logs: true
):
const result = await OpenseaScraper.offers("treeverse", {
debug: true,
logs: true
});
Bring your own puppeteer
if you want to customize the settings for your puppeteer instance you can add your own puppeteer browser instance in the options. 🚧 IMPORTANT: I recommend using stealth plugin as otherwise you most likely won't be able to scrape opensea. If you find a way without using the stealth plugin please report in the form of an issue!
const puppeteer = require('puppeteer-extra');
const StealthPlugin = require('puppeteer-extra-plugin-stealth');
puppeteer.use(StealthPlugin());
const myPuppeteerInstance = await puppeteer.launch(myCustomSettings);
const result = await OpenseaScraper.offer("cool-cats-nft", {
browserInstance: myPuppeteerInstance
});
Demo
npm run demo
Run local console / REPL
To test the functions in an REPL node environment that has OpenseaScraper
service preloaded simply run:
node --experimental-repl-await -i -e "$(< init-dev-env.js)"
I recommend saving an alias:
alias consl='node --experimental-repl-await -i -e "$(< init-dev-env.js)"';
Contribute
Open PR or issue if you would like to have more features added.
Donations 🙏
Thanks for your support!
BTC: bc1qq5qn96ahlqjxfxz2n9l20kem8p9nsz5yzz93f7
ETH: 0x3e4503720Fb8f4559Ecf64BE792b3100722dE940
nftfloorprice.info 🔔
Simple NFT floor price alerts. Easily track all your NFTs and receive realtime email alerts with: https://nftfloorprice.info