puppeteer: Getting HTML from NodeList?

前端 未结 1 1524
南旧
南旧 2021-01-21 15:48

I\'m getting a list of 30 items from the code:

const boxes = await page.evaluate(() => {
    return document.querySelectorAll(\"DIV.a-row.dealContainer.dealTi         


        
相关标签:
1条回答
  • 2021-01-21 16:17

    There are multiple ways to do this:

    • Use page.$$eval to execute the selector and return the result in one step.
    • Use page.evaluate to get the attributes after querying the elements.

    Code sample for page.$$eval

    const htmls = await page.$$eval('selector', el => el.innerHTML);
    

    Code sample for page.evaluate

    const singleBox = boxes[0];
    const html = await page.evaluate(el => el.innerHTML, singleBox);
    
    0 讨论(0)
提交回复
热议问题