You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.3 KiB
52 lines
1.3 KiB
import Hero from '@ulixee/hero'; |
|
import configs from '../config.mjs'; |
|
import HeroBot from './HeroBot.mjs'; |
|
|
|
class Kuaishou extends HeroBot { |
|
|
|
async scrap(url) { |
|
let data = {}; |
|
|
|
try { |
|
let options = { |
|
userAgent: configs.userAgent, |
|
viewport: configs.viewport |
|
}; |
|
|
|
if (this.heroServer) { |
|
options.connectionToCore = this.heroServer; |
|
} |
|
|
|
const profile = await this.init('kuaishou'); |
|
if (profile) { |
|
options.userProfile = profile; |
|
} |
|
|
|
const hero = new Hero(options); |
|
await hero.goto(url, configs.heroBotOptions); |
|
|
|
//等待所有内容加载完成 |
|
const tab = await hero.activeTab; |
|
await tab.waitForLoad('AllContentLoaded', {timeoutMs: configs.heroTabOptions.timeoutMs}); |
|
await hero.waitForPaintingStable(); |
|
|
|
//解析网页HTML数据 |
|
data.title = await hero.document.title; |
|
//data.url = await hero.url; |
|
|
|
const elem = hero.document.querySelector('.video-container-player'); |
|
if (elem) { |
|
data.cover = await elem.getAttribute('poster'); |
|
} |
|
|
|
await hero.close(); |
|
}catch(error) { |
|
console.error("Error got when request %s via hero: %s", url, error); |
|
}; |
|
|
|
return data; |
|
} |
|
|
|
} |
|
|
|
export default Kuaishou;
|
|
|