diff --git a/bot/Douyin.mjs b/bot/Douyin.mjs index 7994d46..536245c 100644 --- a/bot/Douyin.mjs +++ b/bot/Douyin.mjs @@ -1,4 +1,5 @@ import Hero from '@ulixee/hero'; +import configs from '../config.mjs'; class Douyin { constructor(heroCloudServer) { @@ -15,15 +16,11 @@ class Douyin { } const hero = new Hero(options); - await hero.goto(url, { - timeoutMs: 10000, - referrer: 'https://wechat.com', - userAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1' - }); + await hero.goto(url, configs.heroBotOptions); //等待所有内容加载完成 const tab = await hero.activeTab; - await tab.waitForLoad('AllContentLoaded', {timeoutMs: 5000}); + await tab.waitForLoad('AllContentLoaded', {timeoutMs: configs.heroTabOptions.timeoutMs}); const elems = await hero.detach( hero.document.querySelectorAll('meta') ); let meta_name = ''; diff --git a/config.mjs b/config.mjs new file mode 100644 index 0000000..80d5ee7 --- /dev/null +++ b/config.mjs @@ -0,0 +1,15 @@ +export default { + + //请求参数 + heroBotOptions: { + timeoutMs: 10000, + referrer: 'https://wechat.com', + userAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1' + }, + + //网页tab参数 + heroTabOptions: { + timeoutMs: 5000 + } + +}; diff --git a/test/scrap_test.mjs b/test/scrap_test.mjs index 3eae143..5592075 100644 --- a/test/scrap_test.mjs +++ b/test/scrap_test.mjs @@ -6,5 +6,5 @@ import Douyin from '../bot/Douyin.mjs'; const url = 'https://v.douyin.com/iJr1NsJJ/'; console.log('请求中: %s ...', url); const data = await douyin.scrap(url); - console.log('抖音网址 %s 解析结果: %s', url, JSON.stringify(data)); + console.log("解析结果:\n%s", JSON.stringify(data)); })();