' page.goto() '有时有效,但有时无效



我的代码:https://github.com/ItzMiracleOwO/yt-cookier/blob/main/functions/getHeaders.js
所以事情是这样的,page.goto()有时成功地把我带到网站,但有时挂起并卡在about:blank。当它成功时,它返回(resolve)值,但如果它挂起,它什么也不返回。
下面是我的测试脚本:

const cookier = require("ytcf")
const config = require("./credentials.json")
const ytdl = require("ytdl-core")
const fs = require("fs")
let num = 0
async function a() {
try {
num = num + 1
console.log(num)
// await cookier.login({
//     email: config.email,
//     pass: config.pass
// })
const url = "https://www.youtube.com/watch?v=nP_oofP4h28"
const c = await cookier.getCookie(url)
const h = await cookier.getHeaders(url)
console.log(h)
ytdl(url, {
requestOptions: {
headers: {
cookie: c,
h
}
}
}).pipe(fs.createWriteStream('video.mp3'));
a()
} catch (e) {
console.error(e)
}
}
a()

在最初的几次尝试中,它成功地给出了标头,但如果循环继续,它很快就会卡住。只有getHeaders会卡住,但getCookie不会。
getHeadersgetCookie: https://github.com/ItzMiracleOwO/yt-cookier/tree/main/functions
Thanks

这可能是您需要的。我不确定你是想要整个视频还是只是音频:

const ytcf = require("ytcf");
const ytdl = require("ytdl-core");
const fs = require("fs");
// Strips a youtube video's audio and saves it as a mp3 file
// parameters:
//   videoId: the id of the video to strip
//   outputFile: the name of the output file
async function stripAudio(videoLink, outputFile) {
const video = await ytdl(videoLink, {
filter: "audioonly",
quality: "highestaudio",
highWaterMark: 1 << 25,
});
const output = fs.createWriteStream(outputFile);
video.pipe(output);
return new Promise((resolve, reject) => {
output.on("finish", resolve);
output.on("error", reject);
});
}
const videoLink = "https://www.youtube.com/watch?v=nP_oofP4h28";
stripAudio(videoLink, "test.mp3").then(() => {
console.log("done");
});

相关内容

  • 没有找到相关文章

最新更新