I’m trying to extract links of iframe in a webpage it has a section with class
This class a section of video source.
.list-box
After clicking the videos which are in this class it loads the video dynamically without refreshing the page. I tried to automate the click using JS and it didn’t give me links which I tried to achieve using JS. I tried clicking the element with class .list-box every 2 second but it failed giving me the links of iframe.
At first there is video 1 so video 1 has an iframe which is Current video URL, here it does give me the link of the current iframe so there is video 2 which needs to be clicked everytime in order to get the iframe src so for that I tried automating the click but it only give me the link of the Current Video but I want to get the link of every video element which are present.
Here is my JS code
const currentVideoIframe = document.querySelector('iframe');
if (currentVideoIframe) {
console.log('Current url', currentVideoIframe.src);
} else {
console.log('Nothing');
}
// The main element
const videoContainer = document.querySelector(".list-box");
const clickElementEvery2Seconds = () => {
const listBox = document.getElementsByClassName("list-box")[0];
if (listBox) {
listBox.click(); // Initiate click on the list box
// Wait 2 seconds after the click to process iframes
setTimeout(() => {
if (videoContainer) {
const videoIframes = videoContainer.querySelectorAll('iframe');
videoIframes.forEach((iframe, index) => {
const videoUrl = iframe.src;
console.log(`Links ${index + 1}: ${videoUrl}`);
});
} else {
console.log('Nothing');
}
}, 2000); // 2 seconds
} else {
console.log("Element not found");
}
};
setInterval(clickElementEvery2Seconds, 5000);
Thank You for your time. I hope for a help.