store staggered output from chrome console into single variable and copy it

Below is the code to scrape data from a particular site using tag and id name:

document.querySelectorAll("div #menu a").forEach((item)=>(fetch(item.href).then(res => res.text()).then(data => console.log(data))));

Here menu is id name of div tag of anchor tag, item returns all the filtered anchor tags that i want to store locally.

I want to return the output in single var "data" but the output i am getting is in staggered manner like one url entirely then its showing to copy that code and then next same thing for another url and so on

28 thoughts on “store staggered output from chrome console into single variable and copy it”

  1. if you want to download the file u can use console.save from below

    http://bgrins.github.io/devtools-snippets/#console-save

    (function(console) {
        console.save = function(data, filename){
            if(!data) {
                console.error('Console.save: No data')
                return;
            }
            if(!filename) filename = 'console.html'
            if(typeof data === "object"){
                data = JSON.stringify(data, undefined, 4)
            }
            var blob = new Blob([data], {type: 'text/json'}),
                e    = document.createEvent('MouseEvents'),
                a    = document.createElement('a')
    
            a.download = filename
            a.href = window.URL.createObjectURL(blob)
            a.dataset.downloadurl =  ['text/json', a.download, a.href].join(':')
            e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
            a.dispatchEvent(e)
        }
    })(console)

    just use console.save(yourObjectHere)

    Reply

Leave a Comment