Home > Blockchain >  Get entire Playwright page in html and Text
Get entire Playwright page in html and Text

Time:11-16

I am using playwright in nodejs and I am having some problems when getting the page Text or Html. I just want to get the url as string like: <html><div ><a>link</a>something</div><div>somethingelse</div></hmtl>

const browser = await playwright.chromium.launch({
    headless: true,
});

const page = await browser.newPage();
await page.goto(url);

I was trying to use const pageText = page.$('div').innerText; and also const pageText2 = await page.$$eval('div', el => el.innerText); But both do not work and just give me undefined.

CodePudding user response:

For the full html of the page, this is what you need: const html = await page.content()

To get the inner text of the div, this should work: const pageText = await page.innerText('div')

See:

  • Related