0

I would like to run a script in the browser console that will open an array of url's one by one with a few seconds delay between them, better if in the same tab, will copy some data from the page and will insert it into a file and download it after finishing the url's. This is what I got so far, but still not working. Do you know of any alternative to get the this result?

Thanks for the answers.

// website lists
const urlList = ['https://stackoverflow.com/questions/237104/how-do-i-check-if-an-array-includes-a-value-in-javascript?rq=1', 'https://stackoverflow.com/questions/586182/how-to-insert-an-item-into-an-array-at-a-specific-index-javascript?rq=1', 'https://stackoverflow.com/questions/5767325/how-can-i-remove-a-specific-item-from-an-array-in-javascript?rq=1'];

const writeToTextFile = (text, fileName) => {
  let textFile = null;
  const makeTextFile = (text) => {
    const data = new Blob([text], {
      type: 'text/plain',
    });
    if (textFile !== null) {
      window.URL.revokeObjectURL(textFile);
    }
    textFile = window.URL.createObjectURL(data);
    return textFile;
  };
  const link = document.createElement('a');
  link.setAttribute('download', fileName);
  link.href = makeTextFile(text);
  link.click();
};





// variable for keeping track of array position(urls)
let fileData = '###';
let i = 0;

// create interval with 10seconds delay and keep 
// interval reference to clear the event in future
let int = setInterval(() => {
  // update the location with next array value
    
    
  // open the first url and cache the window object reference
let win = window.open(urlList[i], "_blank")
    
  // check value of i and increment, if reached the max value then clear the interval
            
setTimeout(function execute() {
    
         console.log(win.document.getElementsByTagName("h1"));
    fileData = fileData + "###"+win.document.getElementsByTagName("h1");

    
    }, 3000);
    
    

  if (i++ >= urlList.length) {
      writeToTextFile(fileData, 'output.txt');
      clearInterval(int);
}, 6000)
  }
  • Can you give some more details besides "its not working"? For example, the code snippet above isn't formatted legally and just throws a bunch of compile errors; is that the issue you're referring to? Are you having issues with the browser allowing programmatic navigation? Is your file failing to download? Some more details on what's going wrong, along with cleanly formatted example code that can allow others to reproduce the problem, will probably help get you a good answer. – Jake Mar 20 '23 at 01:02

0 Answers0