Skip to content

Instantly share code, notes, and snippets.

@jbass86
Created February 19, 2020 01:53
Show Gist options
  • Save jbass86/3bde8e8d5a63ad2fbd6e822e187258a4 to your computer and use it in GitHub Desktop.
Save jbass86/3bde8e8d5a63ad2fbd6e822e187258a4 to your computer and use it in GitHub Desktop.
dilbert
const get = require("simple-get");
const cheerio = require('cheerio')
const pad = function(num) {
if (num < 10) {
return "0" + num;
} else {
return num;
}
}
let current = new Date();
let url = `https://dilbert.com/strip/${current.getFullYear()}-${pad(current.getMonth() + 1)}-${pad(current.getDate())}`
console.log("url is " + url);
get.concat(url, (error, response, data) => {
if (error) {
console.log("there was error");
console.log(error);
return;
}
let $ = cheerio.load(data.toString());
let thing = $(".img-comic-container img");
let imageURL = "http:" + thing[0].attribs.src;
console.log(imageURL);
get.concat(imageURL, (error, response, imageData) => {
console.log(imageData);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment