Closed
Description
I have the following code:
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://www.amazon.com');
const a = await page.evaluate(() => {
return document.getElementsByTagName('a')
});
console.log(a)
})();
This results in a long list of:
{
'0': {},
'1': {},
'2': {},
'3': { jQuery16409950154717072515: 199 },
'4': { jQuery16409950154717072515: 191 },
'5': {}
}
How do I get the actual DOM from this?
Activity
ebidel commentedon Nov 2, 2017
You can't return the actual page DOM back into a puppeteer script. Those objects live in separate worlds. What you get from
page.evaluate()
is a JSONHandle that you can actual on. By default, this gets serialized (if it can be). So that's what you're seeing.jsonValue()
andgetProperties()
are useful for acting on the return object. For example, if you wanted to get all of the hrefs:What are you trying to do?
ernstbolt commentedon Dec 15, 2017
Thank you! Just what I was looking for!