Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After console.save, the HTML element disappears from the console #72

Open
shingttse24 opened this issue Mar 15, 2017 · 0 comments
Open

Comments

@shingttse24
Copy link

shingttse24 commented Mar 15, 2017

I don't know Javscript syntax so please excuse any mistakes I might be typing.

There is one HTML element from a website I want to write to a text file so that I can read it in Python. I ran this code below intending to do that:

var el = document.getElementsByClassName("exc-param-dr-date hasDatepicker")[0];
el.appendChild(document.createTextNode("Test"));

var tmp = document.createElement("div");
tmp.appendChild(el);

var sh = console.log(tmp.innerHTML);

(function(console){

console.save = function(data, filename){

if(!data) {
    console.error('Console.save: No data')
    return;
}

if(!filename) filename = 'console.json'

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)

console.save(tmp.innerHTML,['to-date.json'])

I was able to successfully write that element to a text file. However, that same element then disappeared from the html code afterwards. How can I avoid this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant