问题描述
过去一周以来,我一直陷入这段代码中。我正在建立我的第一个项目是youtube / instagram视频下载器,使用香草js(jquery的位)和nodejs作为后端语言。我不知道为什么它在开发中不能很好地在生产中工作。
我只是想使用该链接抓取instagram并获取视频链接,以便我可以使用 这是我的视频元素中的src值
*** instaController.js ***
const cheerio = require('cheerio')
const axios = require('axios')
exports.download = async function (req,res,next) {
try {
const html = await axios({
method: 'get',url: req.body.url
})
const $ = cheerio.load(html.data)
const videoLink = $("Meta[property='og:video']").attr("content")
const poster = $("Meta[property='og:image']").attr("content")
const type = $("Meta[property='og:type']").attr("content")
const site = $("Meta[property='og:site_name']").attr("content")
const description = $("Meta[property='og:description']").attr("content")
res.locals.data = {
videoLink,type,site,poster,description
}
next()
} catch (e) {
console.log('axiosError:',e.message)
res.status(200).json({
error: "Something went wrong"
})
}
}
frontendJs.js
const res = await axios({
method: 'post',url: '/download/instagram',data: {
url: input.value
}
})
//console.log(res.data)
if (!res.data.error) {
$('#form-elements').html(res.data)
} else {
alert('danger','Invalid link')
}
*** insta.ejs ***
<%if(data.videoLink){%>
<div class="col-12 mx-auto p-3 p-lg-3 mb-5">
<h3 class="text-center">Long Press/Right Click the Video to download :)</h3>
</div>
<div class="col-12 mx-auto p-3 p-lg-3 video">
<video id="video" src="<%= data.videoLink%>" controls type="<%= data.type%>" poster="<%=data.poster%>"
class="mx-auto" playsinline></video>
</div>
<div class="col-12 insta-details p-1 p-lg-3">
<h2 class="text-center">Info</h2>
<div class="row justify-content-center align-items-center my-4">
<div class="col">Type</div>
<div class="col" id="type"><%= data.site%> <%= data.type%></div>
</div>
<hr>
<div class="row justify-content-center align-items-center">
<div class="col">Description</div>
<div class="col" id="desc"><%= data.description%></div>
</div>
</div>
<%}else{%>
<div class="col-12 insta-details p-1 p-lg-3 d-flex align-items-center justify-content-center">
<h3 class="text-center">Sorry No Such Video or Video from private account :( </h3>
</div>
<%}%>
但是ejs的其他部分会在生产环境中返回,但是在我的localhost中,相同的代码返回ejs的if部分。我非常困惑!请帮助我从这种情况中恢复过来:(预先感谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)