我需要触发所有匹配元素ant的点击,然后将生成的dom读入保存到变量中的dom,如何在不附加dom的情况下从ajax调用中获取dom?
或者我如何将dom加载到某些隐藏的浏览器选项卡中,以使窗口和文档事件气泡成为可能?
let url = 'https://www.amazon.com/dp/B07VHXT1R3';
$.get( url ).then(resp => {
let dom = $( resp );
//images preload
dom.find('#altImages li input').each(function(){
// this would generate other elements inside the dynamic dom,
// but this is stored into a variable
$(this).trigger('click');
});
let images = [];
dom.find('li.image img').each(function(){
// this would have to read the images generated
// but only read one element that comes already rendered
images.push( $(this).data('old-hires') || this.src );
});
[ ... ]
特别是,我需要冒泡进入未渲染的dom,并且不绑定窗口和文档对象
有人知道如何在不使RAM崩溃的情况下做到这一点吗?
我用正则表达式解决了
let images = dom.text().match(/(?<="hiRes":")([^"]+)(?=")/gi).filter( (v, i, s) => { return s.indexOf(v) === i });