dcts / opensea-scraper

Scrapes nft floor prices and additional information from opensea. Used for https://nftfloorprice.info
MIT License
184 stars 73 forks source link

[BUG] Cannot get any result for floor price #55

Closed 0xMarsRover closed 2 years ago

0xMarsRover commented 2 years ago

I cannot get any result for floor price from a NFT on opensea. I used the same code as before (it worked), but now it does not work. I would wonder - is it caused by opensea website upgrade? Thanks.

dcts commented 2 years ago

Can you provide a code snipped and the result you get so I can check what the problem is? Thanks!

0xMarsRover commented 2 years ago
const OpenseaScraper = require("opensea-scraper");

run()

async function run(){
    const options = {
        debug: false,
        logs: false,
        sort: true,
        browserInstance: undefined,
    }

    let nft = 'otherdeed'

    let url = `https://opensea.io/collection/${nft}?search[sortAscending]=true
                &search[sortBy]=PRICE
                &search[toggles][0]=BUY_NOW`
    let resultSize = 5; // if you need less than 32 offers, please use the function offers() instead
    let result =  await OpenseaScraper.offersByScrollingByUrl(url, resultSize, options);
    console.dir(result, {depth: null}); // result object contains keys stats and offers
}

The screenshot of my result is shown below:

328aea9680ae3202ca8c3aae66ea6aa

dcts commented 2 years ago

This is a good catch, as of current state the offersByScrollingByUrl function seems to be broken. In fact, all function that include byScrolling are currently still broken (see open issue #36).

But in the snippet you provided I see no need to use offersByScrolling, you could simply use the offers function:

const OpenseaScraper = require("opensea-scraper");

run();

async function run(){
    const options = {
        debug: false,
        logs: false,
        sort: true,
        browserInstance: undefined,
    };

    let nft = 'otherdeed';
    let result =  await OpenseaScraper.offers(nft, options);
    console.dir(result, {depth: null});
}
0xMarsRover commented 2 years ago

Thanks for your suggestion. It works! I would confirm one thing - if I use offers function, is there a way to control the number of outputs (for example, I'd only get 5 outputs from this function)?

Thanks

dcts commented 2 years ago

offers() and offersByUrl() by default return 32 results (but is currently broken, see #61). The only time it will return less than 32 results is when there are less than 32 items currently on sale (this might happen if you input an url that has a lot of filtering of traits, e.g. OpenseaScraper.offersByUrl("https://opensea.io/collection/boredapeyachtclub?search[sortAscending]=true&search[sortBy]=PRICE&search[stringTraits][0][name]=Clothes&search[stringTraits][0][values][0]=Black%20T&search[stringTraits][1][name]=Eyes&search[stringTraits][1][values][0]=Bored&search[toggles][0]=BUY_NOW"))

I am also not sure if I understand your question correctly. Can you specify:

dcts commented 2 years ago

thanks @kaiqiangh for the fix! 🎉