From 8c960a8c3db7532935794d66f074b52a01760d5b Mon Sep 17 00:00:00 2001 From: filesite Date: Mon, 11 Sep 2023 17:58:58 +0800 Subject: [PATCH] cookies in profile fixed --- bot/Douyin.mjs | 2 +- bot/HeroBot.mjs | 1 + test/douyin_test.mjs | 6 ++++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/bot/Douyin.mjs b/bot/Douyin.mjs index d9746c6..b6e40bd 100644 --- a/bot/Douyin.mjs +++ b/bot/Douyin.mjs @@ -19,7 +19,7 @@ class Douyin extends HeroBot { const profile = await this.init('douyin'); if (profile) { - options.userProfile = this.fixCookies(profile); + options.userProfile = profile; } const hero = new Hero(options); diff --git a/bot/HeroBot.mjs b/bot/HeroBot.mjs index 40385f0..8af2c3a 100644 --- a/bot/HeroBot.mjs +++ b/bot/HeroBot.mjs @@ -75,6 +75,7 @@ class HeroBot { try { //保存profile const profilePath = path.resolve('../tmp/', `profile_${botName}.json`); + profile = this.fixCookies(profile); fs.writeFileSync(profilePath, JSON.stringify(profile, null, 2)); }catch(error) { console.error("Error got when save profile of %s, error detail:\n%s", botName, error); diff --git a/test/douyin_test.mjs b/test/douyin_test.mjs index c0550f5..6fd6307 100644 --- a/test/douyin_test.mjs +++ b/test/douyin_test.mjs @@ -1,14 +1,16 @@ import Hero from '@ulixee/hero'; (async () => { - const hero = new Hero({ connectionToCore: 'ws://192.168.3.13:1818' }); + const hero = new Hero({ + connectionToCore: 'ws://192.168.3.13:1818', + 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' + }); const url = 'https://v.douyin.com/iJr1NsJJ/'; console.log("请求 %s 中。。。", url); 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' }); //const title = await hero.document.title;