Browse Source

add kuaishou livestream support

master
filesite 6 months ago
parent
commit
0c7ae6cae0
  1. 14
      bot/Kuaishou.mjs
  2. 4
      bot/WebCrawler.mjs
  3. 4
      bot/Xigua.mjs
  4. 2
      test/scrap_test.mjs

14
bot/Kuaishou.mjs

@ -39,15 +39,27 @@ class Kuaishou extends HeroBot {
await tab.waitForLoad('DomContentLoaded', {timeoutMs: configs.heroTabOptions.timeoutMs}); await tab.waitForLoad('DomContentLoaded', {timeoutMs: configs.heroTabOptions.timeoutMs});
await hero.waitForPaintingStable({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数据 //解析网页HTML数据
data.title = await hero.document.title; data.title = await hero.document.title;
//data.url = await hero.url; //data.url = await hero.url;
const elem = hero.document.querySelector('.video-container-player'); let elem = await hero.querySelector('.video-container-player');
if (elem) { if (elem) {
data.cover = await elem.getAttribute('poster'); 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 //get cover image's base64 data
if (typeof(data.cover) != 'undefined' && data.cover) { if (typeof(data.cover) != 'undefined' && data.cover) {
data.cover = common.getAbsoluteUrl(data.cover); data.cover = common.getAbsoluteUrl(data.cover);

4
bot/WebCrawler.mjs

@ -42,6 +42,10 @@ class WebCrawler extends HeroBot {
const tab = await hero.activeTab; const tab = await hero.activeTab;
await tab.waitForLoad('DomContentLoaded', {timeoutMs: configs.heroTabOptions.timeoutMs}); 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数据 //解析网页HTML数据
data.title = await hero.document.title; data.title = await hero.document.title;

4
bot/Xigua.mjs

@ -39,6 +39,10 @@ class Xigua extends HeroBot {
await tab.waitForLoad('DomContentLoaded', {timeoutMs: configs.heroTabOptions.timeoutMs}); await tab.waitForLoad('DomContentLoaded', {timeoutMs: configs.heroTabOptions.timeoutMs});
await hero.waitForPaintingStable({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数据 //解析网页HTML数据
data.title = await hero.document.title; data.title = await hero.document.title;

2
test/scrap_test.mjs

@ -52,6 +52,8 @@ import getConfigs from '../config.mjs';
url = 'https://www.kuaishou.com/f/X8FTguiIjZQVwE7'; //pc url = 'https://www.kuaishou.com/f/X8FTguiIjZQVwE7'; //pc
//url = 'https://v.kuaishou.com/7zwqe6'; //mob //url = 'https://v.kuaishou.com/7zwqe6'; //mob
url = 'https://v.kuaishou.com/EvxOVx';
configs.heroTabOptions.timeoutMs = 20000; //所有内容加载完成超时 configs.heroTabOptions.timeoutMs = 20000; //所有内容加载完成超时
configs.userAgent = configs.userAgents.mac_chrome; configs.userAgent = configs.userAgents.mac_chrome;

Loading…
Cancel
Save