LoginSignup
0
0

More than 3 years have passed since last update.

puppeteerでDOM取得したい場合

Posted at
let table = document.querySelector('form[action="mtr1010.asp"] table:nth-of-type(2)');
ReferenceError: document is not defined

puppeteerのスクリプト内でDOM要素の取得がしたい場合
直接document.querySelector()では取得できない。

下記のように page.evaluate()経由で取得する。

page.evaluate(pageFunction[, ...args])

const bodyHandle = await page.$('body');
const html = await page.evaluate(body => body.innerHTML, bodyHandle);
await bodyHandle.dispose();

参考:公式APIドキュメント_puppeteer/puppeteer · GitHub

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0