[英]Problems how to get the src of the iframe that has the sandbox element using cheerio
我正在尝试从iframe
获取 src,但无法获取 url。显然iframe
具有不允许我查看 src 的sandbox
元素。
我正在使用帮助我绕过 cloudflare 块的 cloudscraper 库
没有办法获取 src 值吗?
这是示例代码
const cloudscraper = require('cloudscraper');
const cheerio = require('cheerio');
const main = async() =>{
let url = "https://playerhost.net/show/vikings/01-01?watching=R9rz2SEFDoimDILGkMSwQMtxB";
let res = await cloudscraper(url , {method: 'GET'});
let $ = cheerio.load(res);
const iframeURL = $('iframe').attr('src');
console.log(iframeURL)
};
main();
使用木偶的解决方案
const requestIframeWithAttrSandBox = async(url) =>{
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(url);
const urls = await page.$$eval('iframe', el=> [].map.call(el, d => d.src));
await browser.close();
const _url = urls[0];
return _url
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.