- Save as HAR with content
- Rename file to
har.json
- Download node script
- Modify filter expression
- Run node script.
Last active
March 16, 2019 17:09
-
-
Save Vanuan/9d496f9d53183dcefffdeb2511e4f86a to your computer and use it in GitHub Desktop.
Save images from browser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var json = require('./har'); | |
var fs = require('fs'); | |
function write(filename, base64content) { | |
var fd, content; | |
try { | |
fd = fs.openSync(filename, 'w'); | |
content = Buffer.from(base64content, 'base64'); | |
fs.writeFileSync(fd, content); | |
console.log('written', filename) | |
} catch (err) { | |
console.log(err) | |
/* Handle the error */ | |
} finally { | |
if (fd !== undefined) | |
fs.closeSync(fd); | |
} | |
} | |
var entries = json.log.entries; | |
entries.forEach(entry => { | |
var file = entry['response']['content']; | |
var fileUrl = entry.request.url; | |
if(file.mimeType=='image/jpeg') { | |
var text = file.text; | |
// modify match expression | |
var match = fileUrl.match(/https:\/\/.*\/(.*\.jpg).*/) | |
if(match) { | |
var fileName = match[1]; | |
write('./' + fileName, text); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment