-2

I try to fetch a div with puppeteer and console.log it in my console. The problem is I can't figure out how to fetch a div with a 'name' atribution.


module.exports = {
     name: 'market',
     aliases: ['m'],
     args: false,
     description: 'get market info',
     execute(message, args) {
       async function market() {
           try {
               const URL = 'https://www.binance.com/en/trade/REQ_USDT?layout=basic'
               const browser = await puppeteer.launch()
               const page = await browser.newPage()
               const navigationPromise = page.waitForNavigation({waitUntil: "domcontentloaded"});
               await page.goto(URL)
               await navigationPromise;
            
               let data = await page.evaluate(() => {
                   let results = {}
                   let contents = document.querySelectorAll('.css-104s6ge')
                   contents.forEach((optiune) => {
                       results.push({
                           market1: optiune.querySelector('.css-14d05gv').innerText,
                           market2: optiune.querySelector('.css-1pysja1').innerText,
                           market3: optiune.querySelector('.css-m3c6zl').innerText,
                           market4: optiune.querySelector('.css-vjdxdv').innerText,
                       })
                  })
                   return results;
               })
               console.log(data);
               await browser.close()
           } catch (error) {
               console.error(error)
           }
        }
        
        market();
        
     }
 };

I tried with classes, but I get this error: throw new Error('Unexpected extraInfo events for request ' + responseReceived.requestId);

EDIT: I solved the error by downing the puppeteer version but now I'm getting a blank array.

bogdan
  • 1
  • 1
  • 3
  • 1
    Does this answer your question? [JavaScript get element by name](https://stackoverflow.com/questions/10306129/javascript-get-element-by-name) – Daniel W. Dec 27 '21 at 10:29
  • You are not allowed to scrape those contents: https://www.binance.com/en/terms *You may not i use any deep linking, web crawlers, bots, spiders or other automatic devices, programs, scripts, algorithms or methods, or any similar or equivalent manual processes to access, obtain, copy or monitor any part of the properties...* – Daniel W. Dec 27 '21 at 10:31
  • try getElementByName for js e.g.: document.getElementsByName("css-104s6ge"); – sawan Dec 27 '21 at 10:34

1 Answers1

-1
const elementHandle = await page.$('[name="value"]');

The method runs document.querySelector within the page. If no element matches the selector, the return value resolves to null.

Puppeteer Documentation

Arul Prabakaran
  • 135
  • 2
  • 8