From c22ed86ae4f932505ee082c9738945c2d3842fdf Mon Sep 17 00:00:00 2001 From: chenjunxue <1523825571@qq.com> Date: Fri, 28 Aug 2020 18:45:01 +0800 Subject: [PATCH] 2.2.6 测试添加接口,测试不使用住宅ip --- conf/config.yaml | 4 ++-- lib/facebook.py | 60 +++++++++++++++++++++++++++++++++++------------------------- 2 files changed, 37 insertions(+), 27 deletions(-) diff --git a/conf/config.yaml b/conf/config.yaml index ad9f1bf..bec8a80 100644 --- a/conf/config.yaml +++ b/conf/config.yaml @@ -4,5 +4,5 @@ SERVER: reconnect_interval: 3 VERSION: - code: 115 - name: 2.2.5 \ No newline at end of file + code: 116 + name: 2.2.6 \ No newline at end of file diff --git a/lib/facebook.py b/lib/facebook.py index fe7365b..12992ea 100644 --- a/lib/facebook.py +++ b/lib/facebook.py @@ -158,29 +158,29 @@ class FacebookClient(Client): if how_found == 'profile_friends': data['ref_param'] = 'friends_tab' try: - session = self._state.session_factory(self.user_obj.user_agent) - # res = session.get(url, cookies=self._state.get_cookies()) - if how_found == 'profile_button': - res = self._payload_post("/ajax/add_friend/action.php", data) - else: - proxies = { - "http": "http://8.210.170.163:24000", - "https": "https://8.210.170.163:24000", - } - - url = "https://www.facebook.com/ajax/add_friend/action?" + self._to_url_params(data) - res = session.post(url, cookies=self._state.get_cookies(), data=self._state.get_params(), - proxies=proxies) - content = _util.check_request(res) - j = _util.to_json(content) - # We can't yet, since errors raised in here need to be caught below - _util.handle_payload_error(j) - res = j["payload"] - # 下面是原来的加粉写法 + # session = self._state.session_factory(self.user_obj.user_agent) + # # res = session.get(url, cookies=self._state.get_cookies()) # if how_found == 'profile_button': # res = self._payload_post("/ajax/add_friend/action.php", data) # else: - # res = self._payload_post("/ajax/add_friend/action?" + self._to_url_params(data), {}) + # proxies = { + # "http": "http://8.210.170.163:24000", + # "https": "https://8.210.170.163:24000", + # } + # + # url = "https://www.facebook.com/ajax/add_friend/action?" + self._to_url_params(data) + # res = session.post(url, cookies=self._state.get_cookies(), data=self._state.get_params(), + # proxies=proxies) + # content = _util.check_request(res) + # j = _util.to_json(content) + # # We can't yet, since errors raised in here need to be caught below + # _util.handle_payload_error(j) + # res = j["payload"] + # 下面是原来的加粉写法 + if how_found == 'profile_button': + res = self._payload_post("/ajax/add_friend/action.php", data) + else: + res = self._payload_post("/ajax/add_friend/action?" + self._to_url_params(data), {}) except _exception.FBchatNotLoggedIn: raise except _exception.FBchatFacebookError as err: @@ -1998,11 +1998,21 @@ class FacebookClient(Client): html_text2 = html_text.replace('', '') soup = BeautifulSoup(html_text, 'lxml') script = soup.find_all('script') - de = script[112].prettify() - cursor = re.findall(r'{__m:"__elem_559218ec_0_0"},"(.*?)"\]\],\["StarGrid"', de)[0] - num_list = re.findall(r'pagelet_timeline_app_collection_(.*?):(.*?):(.*?)"', de)[0] - de = script[92].prettify() - pagelet_token = re.findall(r'pagelet_token:"(.*?)"', de)[0] + for key in script: + cursor = re.findall(r'{__m:"__elem_559218ec_0_0"},"(.*?)"\]\],\["StarGrid"', key.prettify()) + if len(cursor): + break + cursor = cursor[0] + for key in script: + num_list = re.findall(r'pagelet_timeline_app_collection_(.*?):(.*?):(.*?)"', key.prettify()) + if len(num_list): + break + num_list = num_list[0] + for key in script: + pagelet_token = re.findall(r'pagelet_token:"(.*?)"', key.prettify()) + if len(pagelet_token): + break + pagelet_token = pagelet_token[0] print(cursor, num_list) cache.set(f'{self.email}:AllPhotosAppCollectionPagelet', num_list) cache.set(f'{self.email}:AllPhotosAppCollectionPagelet:pagelet_token', pagelet_token) -- libgit2 0.24.0