Last active
December 11, 2018 07:51
-
-
Save nektro/3a4c25eb66cb0abf24b84c0239acddbb to your computer and use it in GitHub Desktop.
wallhaven.cc scraper
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
// @author Meghan#2032 <https://nektro.net/> | |
// | |
// | |
const path = require("path"); | |
const fs = require("fs"); | |
const https = require("https"); | |
// | |
https.globalAgent.maxSockets = 25; | |
// | |
function main() | |
{ | |
try { | |
fs.mkdirSync(path.join(__dirname, "files")); | |
} | |
catch {} | |
savePost(1); | |
} | |
function savePost(i) | |
{ | |
const url = "https://wallpapers.wallhaven.cc/wallpapers/full/wallhaven-"+i+".jpg"; | |
const file_name = url.split("/").reverse()[0]; | |
const loc = `${__dirname}/files/${file_name}`; | |
// console.log(`GET ${i}: ${url} ${file_name}`); | |
if (!(fs.existsSync(loc))) { | |
https.get(url, (res) => { | |
if (res.statusCode === 200) { | |
res.pipe(fs.createWriteStream(loc)); | |
console.log(`Saved ${i}: ${url}`); | |
if (i < 730000) savePost(i + 1); | |
} | |
else { | |
const url = "https://wallpapers.wallhaven.cc/wallpapers/full/wallhaven-"+i+".png"; | |
https.get(url, (res) => { | |
res.pipe(fs.createWriteStream(loc)); | |
console.log(`Saved ${i}: ${url}`); | |
if (i < 730000) savePost(i + 1); | |
}); | |
} | |
}); | |
} | |
else { | |
console.log(`Skipping ${url}`); | |
if (i < 730000) savePost(i + 1); | |
} | |
} | |
// | |
// | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment