diff --git a/config/base_config.py b/config/base_config.py index 5d98096..56873b1 100644 --- a/config/base_config.py +++ b/config/base_config.py @@ -1,8 +1,8 @@ # Desc: base config PLATFORM = "xhs" KEYWORDS = "健身,旅游" -LOGIN_TYPE = "qrcode" # qrcode or phone or cookies -COOKIES = "web_session=xxxxcfed1566xxxxxxxxxxxxxxxxxxx;" # if platform is xhs, pleas set only web_session cookie attr +LOGIN_TYPE = "qrcode" # qrcode or phone or cookie +COOKIES = "" # login by cookie, if login_type is cookie, you must set this value # enable ip proxy ENABLE_IP_PROXY = False diff --git a/media_platform/douyin/login.py b/media_platform/douyin/login.py index f02fa9f..e789131 100644 --- a/media_platform/douyin/login.py +++ b/media_platform/douyin/login.py @@ -44,10 +44,10 @@ class DouYinLogin(AbstractLogin): await self.login_by_qrcode() elif self.login_type == "phone": await self.login_by_mobile() - elif self.login_type == "cookies": + elif self.login_type == "cookie": await self.login_by_cookies() else: - raise ValueError("Invalid Login Type Currently only supported qrcode or phone ...") + raise ValueError("Invalid Login Type Currently only supported qrcode or phone or cookie ...") # 如果页面重定向到滑动验证码页面,需要再次滑动滑块 await asyncio.sleep(6) diff --git a/media_platform/xhs/client.py b/media_platform/xhs/client.py index f00904f..0064359 100644 --- a/media_platform/xhs/client.py +++ b/media_platform/xhs/client.py @@ -82,14 +82,14 @@ class XHSClient: async def ping(self) -> bool: """get a note to check if login state is ok""" - utils.logger.info("begin to ping xhs...") + utils.logger.info("Begin to ping xhs...") ping_flag = False try: note_card: Dict = await self.get_note_by_keyword(keyword="小红书") if note_card.get("items"): ping_flag = True except Exception as e: - utils.logger.error(f"ping xhs failed: {e}") + utils.logger.error(f"Ping xhs failed: {e}, and try to login again...") ping_flag = False return ping_flag diff --git a/media_platform/xhs/core.py b/media_platform/xhs/core.py index 1c1d084..620fbe9 100644 --- a/media_platform/xhs/core.py +++ b/media_platform/xhs/core.py @@ -81,7 +81,7 @@ class XiaoHongShuCrawler(AbstractCrawler): utils.logger.info("Begin search xiaohongshu keywords") xhs_limit_count = 20 # xhs limit page fixed value for keyword in config.KEYWORDS.split(","): - utils.logger.info(f"Current keyword: {keyword}") + utils.logger.info(f"Current search keyword: {keyword}") page = 1 while page * xhs_limit_count <= config.CRAWLER_MAX_NOTES_COUNT: note_id_list: List[str] = [] diff --git a/media_platform/xhs/login.py b/media_platform/xhs/login.py index 0e78df1..973691e 100644 --- a/media_platform/xhs/login.py +++ b/media_platform/xhs/login.py @@ -49,7 +49,7 @@ class XHSLogin(AbstractLogin): await self.login_by_qrcode() elif self.login_type == "phone": await self.login_by_mobile() - elif self.login_type == "cookies": + elif self.login_type == "cookie": await self.login_by_cookies() else: raise ValueError("Invalid Login Type Currently only supported qrcode or phone or cookies ...") @@ -172,6 +172,8 @@ class XHSLogin(AbstractLogin): """login xiaohongshu website by cookies""" utils.logger.info("Begin login xiaohongshu by cookie ...") for key, value in utils.convert_str_cookie_to_dict(self.cookie_str).items(): + if key != "web_session": # only set web_session cookie attr + continue await self.browser_context.add_cookies([{ 'name': key, 'value': value,