Reputation: 75
I'm trying to scrape some websites for practise, these websites are javascript rendered sites so I'm using nightmarejs to scrape them, It was working flawless until one time it started to give me blob URL instead of actual .mp4 URL, I looked into chrome dev tools network activity, I see that .m3u8 file is being loaded but in src it shows blob url instead of .m3u8.
Please suggest me what changes shall i make?
Here's my code sample,
app.get("/video/:VideoName", function(req,res){
var VideoName = req.params.VideoName;
request("https://sample.com/videos/"+VideoName, function(err, response, html){
if(!err && response.statusCode == 200){
const $ = cheerio.load(html);
const videoInfo = $(".video-info");
//fetch video link if not already avilable
const includesVideo = VidLinks.find(e => e.name == VideoName)
if (includesVideo) {
res.render("videoPlayer",{episode: includesVideo});
} else {
const Nightmare = require('nightmare')
const nightmare = Nightmare({ show: true })
var iframeLink = videoInfo.find("iframe").attr("src");
iframeLink = iframeLink.replace(/\/\//g, "https://");
const videoLink = nightmare
.goto(iframeLink)
.click("#myVideo")
.evaluate(function(){
//return html
return document.body.innerHTML;
}).end().then(function(body){
//loading html body to cheerio
var $ = cheerio.load(body);
const videoLink = $("#myVideo").find("video").attr("src");
console.log("is this video link? " + videoLink);
return videoLink;
}).then(function(videoLink){
VidLinks.push(videoLink);
res.render("videoPlayer",{video: videoLink});
});
};
} else {
res.send("500 Error, Try Again.");
console.log("ERROR IS HERE! - "+err);
}
});
})
Upvotes: 1
Views: 324