url = "www.w3schools.com/html/html5_video.asp"
VIDEO_LINKS = [];
VIDEO_LIST = [];
function fillVideo(callback) {
request(url, function(err, res, body) {
if (body) {
$ = cheerio.load(body);
}
links = $('source');
$(links).each(function(i, link) {
var value = $(link).attr('src');
if (value.slice(-3) == "mp4" ||
value.slice(-4) == "webm" ||
value.slice(-3) == "ogv") {
VIDEO_LINKS.push(value);
VIDEO_LIST.push($(link).text());
}
})
callback();
});
}
function writeVideo() {
for (j = 0; j < VIDEO_LIST.length; j++) {
request(VIDEO_LINKS[j]).pipe(fs.createWriteStream(VIDEO_LIST[j]));
}
}
fillVideo(writeVideo);
//www.electronicinfo.ca/printable-pdfs
PDF_LINKS = [];
PDF_LIST = [];
function fillPDF(callback) {
request(url, function(err, res, body) {
$ = cheerio.load(body);
links = $('a');
$(links).each(function(i, link) {
var value = $(link).attr('href');
if (value.slice(-3) == "pdf") {
PDF_LINKS.push(value);
PDF_LIST.push($(link).text());
}
})
callback();
});
}
function writePDF() {
for (j = 0; j < PDF_LIST.length; j++) {
request(PDF_LINKS[j]).pipe(fs.createWriteStream(PDF_LIST[j]));
}
}
fillPDF(writePDF);
Hi, This is code that used to work, I changed literally nothing, from about 5 minutes ago, the only thing I changed was duplicating it, and changing variable names. My question is how to fix this code? I know the error is that body is empty, but I dont know how to fix it, i would appeciate any help...