From 0c7ae6cae0a3901f556d3b1e7d1b0ac7aab5cbcb Mon Sep 17 00:00:00 2001 From: filesite Date: Tue, 21 May 2024 10:53:02 +0800 Subject: [PATCH] add kuaishou livestream support --- bot/Kuaishou.mjs | 14 +++++++++++++- bot/WebCrawler.mjs | 4 ++++ bot/Xigua.mjs | 4 ++++ test/scrap_test.mjs | 2 ++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/bot/Kuaishou.mjs b/bot/Kuaishou.mjs index 76bd3d2..df71e83 100644 --- a/bot/Kuaishou.mjs +++ b/bot/Kuaishou.mjs @@ -39,15 +39,27 @@ class Kuaishou extends HeroBot { await tab.waitForLoad('DomContentLoaded', {timeoutMs: configs.heroTabOptions.timeoutMs}); await hero.waitForPaintingStable({timeoutMs: configs.heroTabOptions.timeoutMs}); + let rnd_secods = 10 + parseInt(Math.random() * 10); + console.log("Sleep %s seconds...", rnd_secods); + await common.delay(rnd_secods); + //解析网页HTML数据 data.title = await hero.document.title; //data.url = await hero.url; - const elem = hero.document.querySelector('.video-container-player'); + let elem = await hero.querySelector('.video-container-player'); if (elem) { data.cover = await elem.getAttribute('poster'); } + //增加直播页面的支持,抓取用户的头像做封面图 + if (typeof(data.cover) == 'undefined' || !data.cover) { + elem = await hero.querySelector('.tran .flex img.rounded.ml-10'); + if (elem) { + data.cover = await elem.src; + } + } + //get cover image's base64 data if (typeof(data.cover) != 'undefined' && data.cover) { data.cover = common.getAbsoluteUrl(data.cover); diff --git a/bot/WebCrawler.mjs b/bot/WebCrawler.mjs index 78d784e..12be155 100644 --- a/bot/WebCrawler.mjs +++ b/bot/WebCrawler.mjs @@ -42,6 +42,10 @@ class WebCrawler extends HeroBot { const tab = await hero.activeTab; await tab.waitForLoad('DomContentLoaded', {timeoutMs: configs.heroTabOptions.timeoutMs}); + let rnd_secods = 10 + parseInt(Math.random() * 10); + console.log("Sleep %s seconds...", rnd_secods); + await common.delay(rnd_secods); + //解析网页HTML数据 data.title = await hero.document.title; diff --git a/bot/Xigua.mjs b/bot/Xigua.mjs index 6a4d8f6..53d06f3 100644 --- a/bot/Xigua.mjs +++ b/bot/Xigua.mjs @@ -39,6 +39,10 @@ class Xigua extends HeroBot { await tab.waitForLoad('DomContentLoaded', {timeoutMs: configs.heroTabOptions.timeoutMs}); await hero.waitForPaintingStable({timeoutMs: configs.heroTabOptions.timeoutMs}); + let rnd_secods = 10 + parseInt(Math.random() * 10); + console.log("Sleep %s seconds...", rnd_secods); + await common.delay(rnd_secods); + //解析网页HTML数据 data.title = await hero.document.title; diff --git a/test/scrap_test.mjs b/test/scrap_test.mjs index e040b15..b2225f6 100644 --- a/test/scrap_test.mjs +++ b/test/scrap_test.mjs @@ -52,6 +52,8 @@ import getConfigs from '../config.mjs'; url = 'https://www.kuaishou.com/f/X8FTguiIjZQVwE7'; //pc //url = 'https://v.kuaishou.com/7zwqe6'; //mob + url = 'https://v.kuaishou.com/EvxOVx'; + configs.heroTabOptions.timeoutMs = 20000; //所有内容加载完成超时 configs.userAgent = configs.userAgents.mac_chrome;