使用 PUPPEETER 获取#document 中的元素 [英] Get elements inside #document using PUPPEETER

查看:51
本文介绍了使用 PUPPEETER 获取#document 中的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的,所以你可以帮助我!?

我需要使用 puppetter 在虚拟引用 #document html 中获取一些元素,但是当我尝试时,我收到一条消息,该元素不存在.

以下示例:

HTML

<iframe id="mainFrame"src=...">#文档<头></头><身体><div id="firstDIV"><div id="secondDIV">

<输入类型=文本"id=输入主"name="principalInput">

</html></iframe>

我需要从那个例子中的输入中获取价值.但是 puppeeteer 无法访问 #document

中的任何内容

我正在使用 nodeJS

解决方案

如果我理解正确,您可以尝试这样的操作:

const iframeElement = await page.$('#mainFrame');const frame = await iframeElement.contentFrame();const value = await frame.$eval('#inputMain', input => input.value);

I'm new here, so you can help me!?

I need get some elements inside a virtual reference #document html, using puppetter, but When I try I receive a message it element doesn't exist.

Follow examples:

HTML

<div class="row" id="mainDiv">
    <iframe id="mainFrame" src="...">        
           #document
                <html>
                    <head></head>
                    <body>
                        <div id="firstDIV">
                            <div id="secondDIV">
                            </div>
                            <input type="text" id="inputMain" name="principalInput">
                        </div>
                    </body>
                </html>
    </iframe>
</div>

I need to get value from input in that example. But puppeeteer doesn't access anything inside #document

I'm using nodeJS

解决方案

If I understand correctly, you can try something like this:

const iframeElement = await page.$('#mainFrame');
const frame = await iframeElement.contentFrame();
const value = await frame.$eval('#inputMain', input => input.value);

这篇关于使用 PUPPEETER 获取#document 中的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
前端开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆