diff --git a/downKsVideo/app.js b/downKsVideo/app.js index b4035bc..6bcf6a8 100644 --- a/downKsVideo/app.js +++ b/downKsVideo/app.js @@ -21,13 +21,31 @@ app.use((req, res, next) => { }) app.get('/', async (req, res) => { + let { page } = req.query let data = await request.post(config.visionProfileLikePhotoList, { page: "profile", - pcursor: "空" + pcursor: page }); res.json(data) }) -app.listen(3000, () => { - console.log(`http://127.0.0.1:3000`) +app.get('/tj', async (req, res) => { + let { feeds } = await request.post(config.visionNewRecoFeed, { + dailyFirstPage: false + }); + let result = [] + feeds.forEach(v => { + result.push({ + video_introduce: v.photo.caption, + video_url: v.photo.photoH265Url + }) + }); + + res.json(result) + + +}) + +app.listen(3030, () => { + console.log(`http://127.0.0.1:3030`) }) diff --git a/downKsVideo/data.js b/downKsVideo/data.js new file mode 100644 index 0000000..f877f4e --- /dev/null +++ b/downKsVideo/data.js @@ -0,0 +1,55 @@ +const request = require("./src/http/http"); +const config = require("./src/config/config"); +const fs = require('fs'); + +let result = [] + +// 延迟函数,单位为毫秒 +const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms)); + +const main = async () => { + for (let index = 1; index <= 50; index++) { + try { + let { feeds } = await request.post(config.visionNewRecoFeed, { dailyFirstPage: false }); + console.log(`第: ${index} 次爬`); + console.log(`爬到的数据长度: ${feeds.length}`); + console.log(``); + + feeds.forEach(v => { + result.push({ + video_introduce: v.photo.caption, + video_url: v.photo.photoUrl, + video_img: v.photo.coverUrl + }); + }); + + // 设置延迟时间(例如3000毫秒=3秒) + await delay(1000); // 你可以调整这个值 + + } catch (error) { + console.error(`第 ${index} 次请求出错:`, error); + // 出错时也等待一段时间再继续 + await delay(3000); + } + } + + // 先读取现有数据,然后追加新数据 + fs.readFile('data.json', 'utf8', (err, data) => { + if (err) { + console.error('读取文件出错:', err); + return; + } + const existingData = JSON.parse(data); + console.log(`data.json 原文件数据长度: ${existingData.length}`); + console.log(`爬到的新数据长度: ${result.length}`); + const updatedData = [...existingData, ...result]; + console.log(`合并后总数据长度: ${updatedData.length}`); + + fs.writeFile('data.json', JSON.stringify(updatedData, null, 2), (err) => { + if (err) console.error('写入文件出错:', err); + else console.log('数据已成功追加到data.json'); + }); + }); +} + +main(); \ No newline at end of file diff --git a/downKsVideo/index.html b/downKsVideo/index.html index 95b1424..0765239 100644 --- a/downKsVideo/index.html +++ b/downKsVideo/index.html @@ -4,6 +4,7 @@