problem description
Liberal arts scum recently needed to get a broadcast link to a website, wrote a node crawler, and the array of all links can be printed, but I don"t know how to get an array of these links with a variable.
related codes
var http = require("https");
var cheerio = require("cheerio")
var url = "https://www.tagesschau.de/export/podcast/tagesschau_https/";
function get(url) {
return new Promise(function (resolve, reject) {
http.get(url, function (res) {
var html = "";
res.on("data", function (data) {
html += data;
});
res.on("end", function () {
resolve(html);
});
}).on("error", function (e) {
reject(e)
console.log("");
});
})
}
function filterChapter(html) {
var x = []
const $ = cheerio.load(html);
const chapters = $("enclosure");
chapters.each(function (i, item) {
x.push(item.attribs.url)
})
console.log(x)
}
get(url).then(function (data) {
filterChapter(data)
})
Is there any way to get this x array in filterChapter? If it is returned, it seems to be returned directly to the anonymous function after then, but it is still not available. Another problem with
is getting all the enclosure tags, each with a url= "." This kind of information, I want to get the link how to write? Although I can get the link above, it looks strange. I don"t understand the parameters after each. Thank you!