因为我是编程新手,所以我想很快就能找到解决方案。我尝试使用节点包youtube-info抓取YouTube数据。在我的数据库中有VideoIds和爬行值。
基本上我的函数是有效的,但是大约每2个条目就是一个错误,尽管is是正确的。我怀疑这是时间/查询问题
const mysql = require('mysql2/promise')
const pool = mysql.createPool({
host : '***',
user : '***',
password : '***',
database : '***',
waitForConnections: true,
connectionLimit: 10,
queueLimit: 0
})
let videos = []
async function getVideosToCrawl() {
await pool.query('SELECT * FROM youtubeVideos', (err, rows) => {
if (err) throw err
for (let item of rows){
videos.push(item.videoID)
console.log(item.videoID)
}
for (let item of videos){
fetchVideoInfo(item).then(function (videoInfo) {
console.log(videoInfo)
})
}
})
}
getVideosToCrawl(){
videoId: '_JpDImQn8vE',
url: 'https://www.youtube.com/watch?v=_JpDImQn8vE',
title: 'El Mejor DÍA y HORA Para Publicar Videos en Youtube 2020',
description: 'Como opciones.',
owner: 'Aletz84',
channelId: 'UCniy9BkhRl3ld7SHTNjgiaw',
thumbnailUrl: 'https://i.ytimg.com/vi/_JpDImQn8vE/maxresdefault.jpg',
embedURL: undefined,
datePublished: '2020-05-30',
genre: 'Howto & Style',
paid: false,
unlisted: false,
isFamilyFriendly: true,
duration: 333,
views: 1990,
regionsAllowed: [
'AD', 'AE', 'AF', 'AG', 'AI', 'AL', 'AM', 'AO', 'AQ', 'AR',
'AS', 'AT', 'AU', 'AW', 'AX', 'AZ', 'BA', 'BB', 'BD', 'BE',
'BF', 'BG', 'BH', 'BI', 'BJ', 'BL', 'BM', 'BN', 'BO', 'BQ',
'BR', 'BS', 'BT', 'BV', 'BW', 'BY', 'BZ', 'CA', 'CC', 'CD',
'CF', 'CG', 'CH', 'CI', 'CK', 'CL', 'CM', 'CN', 'CO', 'CR',
'CU', 'CV', 'CW', 'CX', 'CY', 'CZ', 'DE', 'DJ', 'DK', 'DM',
'DO', 'DZ', 'EC', 'EE', 'EG', 'EH', 'ER', 'ES', 'ET', 'FI',
'FJ', 'FK', 'FM', 'FO', 'FR', 'GA', 'GB', 'GD', 'GE', 'GF',
'GG', 'GH', 'GI', 'GL', 'GM', 'GN', 'GP', 'GQ', 'GR', 'GS',
'GT', 'GU', 'GW', 'GY', 'HK', 'HM', 'HN', 'HR', 'HT', 'HU',
... 149 more items
],
dislikeCount: 9,
likeCount: 256,
channelThumbnailUrl: 'https://yt3.ggpht.com/a/AATXAJxo4b4LfwRTPwiINRneCgYMJYIDT_YqodCM5UzT-w=s48-c-k-c0xffffffff-no-rj-mo',
commentCount: 126
}
Unhandled rejection Error: Video does not exist
at C:\Users\olli9\OneDrive\Coding\YouTube\node_modules\youtube-info\index.js:19:13
at tryCatcher (C:\Users\olli9\OneDrive\Coding\YouTube\node_modules\bluebird\js\release\util.js:16:23)
at Promise._settlePromiseFromHandler (C:\Users\olli9\OneDrive\Coding\YouTube\node_modules\bluebird\js\release\promise.js:547:31)
at Promise._settlePromise (C:\Users\olli9\OneDrive\Coding\YouTube\node_modules\bluebird\js\release\promise.js:604:18)
at Promise._settlePromise0 (C:\Users\olli9\OneDrive\Coding\YouTube\node_modules\bluebird\js\release\promise.js:649:10)
at Promise._settlePromises (C:\Users\olli9\OneDrive\Coding\YouTube\node_modules\bluebird\js\release\promise.js:729:18)
at _drainQueueStep (C:\Users\olli9\OneDrive\Coding\YouTube\node_modules\bluebird\js\release\async.js:93:12)
at _drainQueue (C:\Users\olli9\OneDrive\Coding\YouTube\node_modules\bluebird\js\release\async.js:86:9)
at Async._drainQueues (C:\Users\olli9\OneDrive\Coding\YouTube\node_modules\bluebird\js\release\async.js:102:5)
at Immediate.Async.drainQueues [as _onImmediate] (C:\Users\olli9\OneDrive\Coding\YouTube\node_modules\bluebird\js\release\async.js:15:14)
at processImmediate (internal/timers.js:456:21)发布于 2020-07-15 04:12:25
问题解决了!为了更好地为将来做好准备,我直接切换到了YouTube应用编程接口。
https://stackoverflow.com/questions/62538216
复制相似问题