Skip to content

Commit

Permalink
fix: 站点仿真签到
Browse files Browse the repository at this point in the history
  • Loading branch information
linyuan0213 committed Jul 19, 2024
1 parent 6a3e4d1 commit 77c1aac
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
10 changes: 9 additions & 1 deletion app/helper/drissionpage_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
37 changes: 30 additions & 7 deletions app/plugins/modules/autosignin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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()
Expand Down Expand Up @@ -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
})

# 周期运行
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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)))
Expand Down
2 changes: 1 addition & 1 deletion app/sites/siteconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 77c1aac

Please sign in to comment.