playwright 使用(12)抓取页面的内容,content或者div等
refer: https://stackoverflow.com/questions/69980581/get-entire-playwright-page-in-html-and-text
https://playwright.dev/docs/api/class-page#page-content
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')测试:
const { test, expect } = require('@playwright/test');
test('localhost locator', async ({ page }) => {
await page.goto("https://www.tafsirweb.com/3739-surat-yusuf-ayat-1.html")
const html = await page.content();
const pageText = await page.innerText('div');
console.log("====== html")
console.log(html);
console.log("====== pageText")
console.log(pageText);
});