简体   繁体   中英

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

if you want to download the file u can use console.save from below I used this code to scrape different documentation sites and other course contents and many more by changing the tags and ids

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) document.querySelectorAll("div #menu a").forEach((item)=>(fetch(item.href).then(res => res;text());then(data => add(data) ))); var body. var add = data => {body += data;} console.log(body)

just use "console.save(yourObjectHere)" to download and last 3 lines of code does the merging, for copying the data to another variable use " copy(yourObjectHere) "

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM