From 77c1aacf9d66b2a0369eaf54abbb594a8df8408d Mon Sep 17 00:00:00 2001 From: "C.C" Date: Fri, 19 Jul 2024 08:16:41 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=AB=99=E7=82=B9=E4=BB=BF=E7=9C=9F?= =?UTF-8?q?=E7=AD=BE=E5=88=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helper/drissionpage_helper.py | 10 ++++++++- app/plugins/modules/autosignin.py | 37 +++++++++++++++++++++++++------ app/sites/siteconf.py | 2 +- 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/app/helper/drissionpage_helper.py b/app/helper/drissionpage_helper.py index 259f91cc..45e3f34b 100644 --- a/app/helper/drissionpage_helper.py +++ b/app/helper/drissionpage_helper.py @@ -69,7 +69,7 @@ def get_page_html(self, self.co.set_timeouts(base=timeout, script=5) if ua: self.co.set_user_agent(user_agent=ua) - page = ChromiumPage(self.co) + page = ChromiumPage(self.co, timeout=180) page.set.load_mode.none() page.get(url, retry=3) if cookies: @@ -87,6 +87,14 @@ def get_page_html(self, callback(page) except Exception as e: logger.error(f"url: {url} 回调函数执行失败: {e}") + # 嵌入CF处理 + if 'TurnstileCallback' in page.html: + page.wait(10) + success, _ = self.sync_cf_retry(page) + if not success: + logger.debug(f"url: {url} Cloudflare 等待超时") + return "" + logger.debug(f"url: {url} 获取网页源码成功") content = page.html else: diff --git a/app/plugins/modules/autosignin.py b/app/plugins/modules/autosignin.py index 6a97f2e4..5ecc30ae 100644 --- a/app/plugins/modules/autosignin.py +++ b/app/plugins/modules/autosignin.py @@ -181,6 +181,21 @@ def get_fields(): ] ] }, + { + 'type': 'details', + 'summary': '仿真站点', + 'tooltip': '只有选中的站点才会开启仿真', + 'content': [ + # 同一行 + [ + { + 'id': 'emulate_sites', + 'type': 'form-selectgroup', + 'content': sites + }, + ] + ] + }, ] def init_config(self, config=None): @@ -197,6 +212,7 @@ def init_config(self, config=None): self._queue_cnt = config.get("queue_cnt") self._onlyonce = config.get("onlyonce") self._clean = config.get("clean") + self._emulate_sites = config.get("emulate_sites") or [] # 定时服务 self._scheduler = SchedulerService() @@ -244,7 +260,8 @@ def run_service(self): "notify": self._notify, "onlyonce": self._onlyonce, "queue_cnt": self._queue_cnt, - "clean": self._clean + "clean": self._clean, + "emulate_sites": self._emulate_sites }) # 周期运行 @@ -310,11 +327,18 @@ def sign_in(self, event=None): return # 查询签到站点 + emulate_sites = set(self._emulate_sites).intersection(set(sign_sites)) sign_sites = Sites().get_sites(siteids=sign_sites) if not sign_sites: self.info("没有可签到站点,停止运行") return + new_sign_sites = [] + for site in sign_sites: + if str(site.get("id")) in emulate_sites: + site['chrome'] = True + new_sign_sites.append(site) + sign_sites = new_sign_sites # 执行签到 self.info("开始执行签到任务") with ThreadPool(min(len(sign_sites), int(self._queue_cnt) if self._queue_cnt else 10)) as p: @@ -469,7 +493,7 @@ def __signin_base(self, site_info): html_text = '' while tries > 0: try: - html_text = chrome.get_page_html(url=home_url, ua=ua, cookies=site_cookie, proxies=site_info.get("proxy")) + html_text = chrome.get_page_html(url=home_url, ua=ua, cookies=site_cookie, proxies=Config().get_proxies() if site_info.get("proxy") else None) if html_text: break except Exception as e: @@ -488,7 +512,7 @@ def __signin_base(self, site_info): xpath_str = xpath break if re.search(r'已签|签到已得', html_text, re.IGNORECASE) \ - and not xpath_str: + and xpath_str: self.info("%s 今日已签到" % site) return f"【{site}】今日已签到" if not xpath_str: @@ -507,7 +531,7 @@ def __signin_base(self, site_info): html_text = chrome.get_page_html(url=home_url, ua=ua, cookies=site_cookie, - proxies=site_info.get("proxy"), + proxies=Config().get_proxies() if site_info.get("proxy") else None, callback=lambda page: page(f'x:{xpath_str}').click(by_js=True)) if html_text: break @@ -522,9 +546,8 @@ def __signin_base(self, site_info): # 判断是否已签到 [签到已得125, 补签卡: 0] if re.search(r'已签|签到已得', html_text, re.IGNORECASE): - return f"【{site}】签到成功" - self.info("%s 仿真签到成功" % site) - return f"【{site}】仿真签到成功" + self.info("%s 仿真签到成功" % site) + return f"【{site}】仿真签到成功" except Exception as e: ExceptionUtils.exception_traceback(e) self.warn("%s 仿真签到失败:%s" % (site, str(e))) diff --git a/app/sites/siteconf.py b/app/sites/siteconf.py index 165372ac..4caef320 100644 --- a/app/sites/siteconf.py +++ b/app/sites/siteconf.py @@ -268,7 +268,7 @@ def __get_site_page_html(url, cookie, ua, headers=None, render=False, proxy=Fals html_text = '' while tries > 0: try: - html_text = chrome.get_page_html(url=url, cookies=cookie, ua=ua, proxies=proxy) + html_text = chrome.get_page_html(url=url, cookies=cookie, ua=ua, proxies=Config().get_proxies() if proxy else None) if html_text: return html_text except Exception as e: