From e9a2f50246cc8db89140f710c001cddf69ec9791 Mon Sep 17 00:00:00 2001 From: chenjunxue <1523825571@qq.com> Date: Mon, 7 Sep 2020 11:21:31 +0800 Subject: [PATCH] 2.3.7 增加解封具体方式 --- conf/config.yaml | 4 ++-- core/callback.py | 4 ++-- core/monitor.py | 5 ++++- lib/state.py | 42 +++++++++++++++++++++++------------------- utils/cache.py | 2 +- utils/parse_html.py | 25 ++++++++++++++++++++----- 6 files changed, 52 insertions(+), 30 deletions(-) diff --git a/conf/config.yaml b/conf/config.yaml index 8a249d1..65d76c0 100644 --- a/conf/config.yaml +++ b/conf/config.yaml @@ -4,5 +4,5 @@ SERVER: reconnect_interval: 3 VERSION: - code: 126 - name: 2.3.6 \ No newline at end of file + code: 127 + name: 2.3.7 \ No newline at end of file diff --git a/core/callback.py b/core/callback.py index 58cb4bf..d5f6180 100644 --- a/core/callback.py +++ b/core/callback.py @@ -98,7 +98,7 @@ class CallBack(): body={'event': 'onUpdateMyInfo', 'info': client.info()} ) - def onLoggingError(self, email, reason): + def onLoggingError(self, email, reason, verification_method: list): u = models.UserList.get(email=email) if u: u.set(status=common.Status.FAILED, token=None) @@ -106,7 +106,7 @@ class CallBack(): self._notify_( type_="account", client=client, - body={'event': 'onLoginFailed', 'reason': reason} + body={'event': 'onLoginFailed', 'reason': reason, 'verification_method': verification_method} ) def onLogout(self, client): diff --git a/core/monitor.py b/core/monitor.py index 6ccc495..08864ba 100644 --- a/core/monitor.py +++ b/core/monitor.py @@ -29,6 +29,7 @@ from lib.facebook import FacebookClient from lib.ttl_cache import lru_cache from lib.websock import Client from utils import parameter, system_info +from utils.cache import cache log = logging.getLogger(__name__) tostr = lambda x: (x) @@ -131,7 +132,9 @@ class Monitor(callback.CallBack): self.onLoggedIn(client) return client.info() except Exception as err: - self.onLoggingError(email, str(err)) + verification_method = cache.get(f'{email}:verification_method', []) + cache.delete(f'{email}:verification_method') + self.onLoggingError(email, str(err), verification_method) raise err def close_selenium(self, email, browser): diff --git a/lib/state.py b/lib/state.py index 7bef98f..68b923d 100644 --- a/lib/state.py +++ b/lib/state.py @@ -17,6 +17,7 @@ from requests import Session as Session_ from lib import common, graph from utils import parse_html, encpass +from utils.cache import cache class Session(Session_): @@ -37,7 +38,9 @@ class Session(Session_): content = res.text set_cookie = res.headers.get('Set-Cookie', None) if 'checkpoint' in res.url: - # self.get_deal_lock_method(int(kwargs['data']['jazoest']), kwargs['data']['lsd']) + way_list = self.get_verification_method(**kwargs) + email = kwargs['data']['email'] + cache.set(key=f'{email}:verification_method', value=way_list) raise FBchatUserError('账号被封锁:' + parse_html.checkpoint_text(content)) elif 'ServerRedirect' in content and self._match_redirect_(content) == '\\/checkpoint\\/block\\/': raise FBchatUserError('账号被封锁') @@ -61,7 +64,7 @@ class Session(Session_): hasattr(self, 'logout_call') and self.logout_call() raise - def get_init_lock_args(self, jazoest: str, lsd: str): + def verification_init(self, **kwargs): """ 获取解封方式 所需要参数 """ @@ -73,26 +76,27 @@ class Session(Session_): 'modules': 'FormSubmit', "dpr": 2, "fb_dtsg_ag": fb_dtsg_ag, - "jazoest": jazoest, + "jazoest": int(kwargs['data']['jazoest']), "nh": nh, - "lsd": lsd + "lsd": kwargs['data']['lsd'] } return params - def get_deal_lock_method(self, jazoest, lsd): - params = self.get_init_lock_args(jazoest, lsd) - res = super().request('GET', 'https://www.facebook.com/ajax/bootloader-endpoint', - params=params) - - res = super().request('POST', 'https://www.facebook.com/cookie/consent/', - params=params) - - params['submit[Continue]'] = 'Continue' - res = super().request('POST', - 'https://www.facebook.com/checkpoint/async?next' - , data=params - ) - pass + def get_verification_method(self, **kwargs): + """ + 获取解封方法 + """ + try: + params = self.verification_init(**kwargs) + # res = super().request('POST', 'https://www.facebook.com/cookie/consent/',params=params) + # res = super().request('GET', 'https://www.facebook.com/ajax/bootloader-endpoint',params=params) + params['submit[Continue]'] = 'Continue' + res = super().request('POST', 'https://www.facebook.com/checkpoint/async?next', data=params) + res = super().request('GET', 'https://zh-cn.facebook.com/checkpoint/?next') + way_list = parse_html.get_verification_method(res.text) + return way_list # 解封方式在里面 + except: + return [] class PCState(State): @@ -162,7 +166,7 @@ class PCState(State): 'lgnjs': int(time.time()), 'timezone': '-480' }) - r = session.post('https://www.facebook.com/login/device-based/regular/login/?login_attempt=1&lwv=110', + r = session.post('https://zh-cn.facebook.com/login/device-based/regular/login/?login_attempt=1&lwv=110', data=data) setCookie = r.headers.get('Set-Cookie') or '' diff --git a/utils/cache.py b/utils/cache.py index 03c56c9..174949a 100644 --- a/utils/cache.py +++ b/utils/cache.py @@ -7,4 +7,4 @@ # @Software: PyCharm import cacheout -cache = cacheout.LRUCache(maxsize=5000) \ No newline at end of file +cache = cacheout.LRUCache(maxsize=5000) diff --git a/utils/parse_html.py b/utils/parse_html.py index a8d90aa..c69141a 100644 --- a/utils/parse_html.py +++ b/utils/parse_html.py @@ -545,11 +545,13 @@ def checkpoint_text(text): try: b = bs4.BeautifulSoup(text, 'html.parser') c = b.find('form', class_='checkpoint') - for mark in ['span', 'p', 'h3', 'strong']: - content = ''.join([k.text for k in c.find_all(mark)]) - if content: - return content - return "" + if 'captcha_persist_data' not in text: + for mark in ['span', 'p', 'h3', 'div']: + content = ''.join(set([k.text for k in c.find_all(mark)])) + if content: + return content + else: + return '进行人机身份验证' except: return "" @@ -566,6 +568,19 @@ def get_lock_init(text): return '' +def get_verification_method(text): + """ + 获取facebook锁定后的解锁方式 + """ + try: + b = bs4.BeautifulSoup(text, 'html.parser') + c_list = b.find_all('div', class_='uiInputLabel clearfix') + span_list = [c.find_all('span')[1].text for c in c_list] + return span_list + except: + return [] + + def get_location_info(html): try: selector = etree.HTML(html) -- libgit2 0.24.0