gpt4 book ai didi

javascript - Node JS 从 url 获取所有 iframe

转载 作者:搜寻专家 更新时间:2023-11-01 00:39:11 24 4
gpt4 key购买 nike

我有一个无法更改的静态网页,我需要获取此网页上的所有 iframe。 iframe 没有 ID 或名称。他们看起来像这样

<iframe height="584" width="630" src="someurl" scrolling="auto" noresize="" frameborder="0"></iframe>

所以,我可以通过模块请求获取“主页”内容,但我不知道如何遍历它并找到所有 iframe 元素及其来源!

希望能帮到你

扣篮 toast

最佳答案

名为cheerio 的 Node 模块是一个类似 Node 的 jQuery 替代品。您可以加载“主页”的内容,然后像这样获取所有 iframe:

var cheerio = require('cheerio')
var $ = cheerio.load(mainPageContent);

$('iframe').each(function(index, element) {
var url = $(element).attr('src'); // --> Get the URL of the iframe

// Do something with the URL of the iframe here
});

关于javascript - Node JS 从 url 获取所有 iframe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41027262/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com