正在显示
3 个修改的文件
包含
116 行增加
和
6 行删除
| @@ -22,6 +22,7 @@ from uuid import uuid1 | @@ -22,6 +22,7 @@ from uuid import uuid1 | ||
| 22 | import demjson | 22 | import demjson |
| 23 | import furl | 23 | import furl |
| 24 | import retrying | 24 | import retrying |
| 25 | +from bs4 import BeautifulSoup | ||
| 25 | from fbchat import (Client, FBchatException, FBchatUserError, Message, Sticker, | 26 | from fbchat import (Client, FBchatException, FBchatUserError, Message, Sticker, |
| 26 | ThreadType, _exception, _graphql, _util, log) | 27 | ThreadType, _exception, _graphql, _util, log) |
| 27 | 28 | ||
| @@ -32,6 +33,7 @@ from lib.graph import GraphAPIError | @@ -32,6 +33,7 @@ from lib.graph import GraphAPIError | ||
| 32 | from lib.state import PCState | 33 | from lib.state import PCState |
| 33 | from lib.ttl_cache import lru_cache | 34 | from lib.ttl_cache import lru_cache |
| 34 | from utils import _attachment, parse_html | 35 | from utils import _attachment, parse_html |
| 36 | +from utils.cache import cache | ||
| 35 | 37 | ||
| 36 | 38 | ||
| 37 | class PostParam(Enum): | 39 | class PostParam(Enum): |
| @@ -150,14 +152,35 @@ class FacebookClient(Client): | @@ -150,14 +152,35 @@ class FacebookClient(Client): | ||
| 150 | "to_friend": fbid, | 152 | "to_friend": fbid, |
| 151 | "action": "add_friend", | 153 | "action": "add_friend", |
| 152 | "how_found": how_found, | 154 | "how_found": how_found, |
| 155 | + "logging_location": 'friends_center', | ||
| 156 | + "floc": 'pymk' | ||
| 153 | } | 157 | } |
| 154 | if how_found == 'profile_friends': | 158 | if how_found == 'profile_friends': |
| 155 | data['ref_param'] = 'friends_tab' | 159 | data['ref_param'] = 'friends_tab' |
| 156 | try: | 160 | try: |
| 161 | + session = self._state.session_factory(self.user_obj.user_agent) | ||
| 162 | + # res = session.get(url, cookies=self._state.get_cookies()) | ||
| 157 | if how_found == 'profile_button': | 163 | if how_found == 'profile_button': |
| 158 | res = self._payload_post("/ajax/add_friend/action.php", data) | 164 | res = self._payload_post("/ajax/add_friend/action.php", data) |
| 159 | else: | 165 | else: |
| 160 | - res = self._payload_post("/ajax/add_friend/action?" + self._to_url_params(data), {}) | 166 | + proxies = { |
| 167 | + "http": "http://8.210.170.163:24000", | ||
| 168 | + "https": "https://8.210.170.163:24000", | ||
| 169 | + } | ||
| 170 | + | ||
| 171 | + url = "https://www.facebook.com/ajax/add_friend/action?" + self._to_url_params(data) | ||
| 172 | + res = session.post(url, cookies=self._state.get_cookies(), data=self._state.get_params(), | ||
| 173 | + proxies=proxies) | ||
| 174 | + content = _util.check_request(res) | ||
| 175 | + j = _util.to_json(content) | ||
| 176 | + # We can't yet, since errors raised in here need to be caught below | ||
| 177 | + _util.handle_payload_error(j) | ||
| 178 | + res = j["payload"] | ||
| 179 | + # 下面是原来的加粉写法 | ||
| 180 | + # if how_found == 'profile_button': | ||
| 181 | + # res = self._payload_post("/ajax/add_friend/action.php", data) | ||
| 182 | + # else: | ||
| 183 | + # res = self._payload_post("/ajax/add_friend/action?" + self._to_url_params(data), {}) | ||
| 161 | except _exception.FBchatNotLoggedIn: | 184 | except _exception.FBchatNotLoggedIn: |
| 162 | raise | 185 | raise |
| 163 | except _exception.FBchatFacebookError as err: | 186 | except _exception.FBchatFacebookError as err: |
| @@ -1965,9 +1988,86 @@ class FacebookClient(Client): | @@ -1965,9 +1988,86 @@ class FacebookClient(Client): | ||
| 1965 | """ | 1988 | """ |
| 1966 | 你的照片 | 1989 | 你的照片 |
| 1967 | """ | 1990 | """ |
| 1968 | - #如果cursor为None,则请求 https://www.facebook.com/ana.sofia.583671/photos_all 获取到 | ||
| 1969 | - return | ||
| 1970 | - ###############graph接口 start ############## | 1991 | + # 如果cursor为None,则请求 https://www.facebook.com/ana.sofia.583671/photos_all 获取到 |
| 1992 | + if cursor is None or cursor == '': | ||
| 1993 | + url = 'https://www.facebook.com/ana.sofia.583671/photos_all' | ||
| 1994 | + try: | ||
| 1995 | + session = self._state.session_factory(self.user_obj.user_agent) | ||
| 1996 | + res = session.get(url, cookies=self._state.get_cookies()) | ||
| 1997 | + html_text = res.text | ||
| 1998 | + html_text2 = html_text.replace('<!-- ', '').replace(' -->', '') | ||
| 1999 | + soup = BeautifulSoup(html_text, 'lxml') | ||
| 2000 | + script = soup.find_all('script') | ||
| 2001 | + de = script[112].prettify() | ||
| 2002 | + cursor = re.findall(r'{__m:"__elem_559218ec_0_0"},"(.*?)"\]\],\["StarGrid"', de)[0] | ||
| 2003 | + num_list = re.findall(r'pagelet_timeline_app_collection_(.*?):(.*?):(.*?)"', de)[0] | ||
| 2004 | + de = script[92].prettify() | ||
| 2005 | + pagelet_token = re.findall(r'pagelet_token:"(.*?)"', de)[0] | ||
| 2006 | + print(cursor, num_list) | ||
| 2007 | + cache.set(f'{self.email}:AllPhotosAppCollectionPagelet', num_list) | ||
| 2008 | + cache.set(f'{self.email}:AllPhotosAppCollectionPagelet:pagelet_token', pagelet_token) | ||
| 2009 | + except Exception as err: | ||
| 2010 | + raise BaseException(f'获取必要参数错误{err}') | ||
| 2011 | + soup = BeautifulSoup(html_text2, 'lxml') | ||
| 2012 | + lis = soup.find_all("li", {"class": "fbPhotoStarGridElement"}) | ||
| 2013 | + data_list = list() | ||
| 2014 | + for li in lis: | ||
| 2015 | + pic_id = li.attrs.get('data-fbid', None) | ||
| 2016 | + url = li.attrs.get('data-starred-src', None) | ||
| 2017 | + label = li.a.attrs.get('aria-label', None) | ||
| 2018 | + data = { | ||
| 2019 | + 'pic_id': pic_id, | ||
| 2020 | + 'url': url, | ||
| 2021 | + 'label': label | ||
| 2022 | + } | ||
| 2023 | + data_list.append(data) | ||
| 2024 | + res = { | ||
| 2025 | + 'data_list': data_list, | ||
| 2026 | + 'cursor': cursor | ||
| 2027 | + } | ||
| 2028 | + return res | ||
| 2029 | + else: | ||
| 2030 | + num_list = cache.get(f'{self.email}:AllPhotosAppCollectionPagelet') | ||
| 2031 | + pagelet_token = cache.get(f'{self.email}:AllPhotosAppCollectionPagelet:pagelet_token') | ||
| 2032 | + assert num_list is not None, '游标失效,请重新获取首页游标。' | ||
| 2033 | + get_data = {"collection_token": f"{num_list[0]}:{num_list[1]}:{num_list[2]}", | ||
| 2034 | + "cursor": cursor, | ||
| 2035 | + "disablepager": False, "overview": False, "profile_id": num_list[0], | ||
| 2036 | + "pagelet_token": pagelet_token, | ||
| 2037 | + "tab_key": "photos", "lst": f"{num_list[0]}:{num_list[0]}:{str(int(time.time()))}", | ||
| 2038 | + "order": None, | ||
| 2039 | + "sk": "photos", "importer_state": None} | ||
| 2040 | + data = {'data': json.dumps(get_data), | ||
| 2041 | + 'fb_dtsg_ag': self._state.fb_dtsg_ag, | ||
| 2042 | + 'dpr': 2, | ||
| 2043 | + 'jazoest': self._state.jazoest | ||
| 2044 | + } | ||
| 2045 | + try: | ||
| 2046 | + url = furl.furl("https://www.facebook.com/ajax/pagelet/generic.php/AllPhotosAppCollectionPagelet").add( | ||
| 2047 | + data).url | ||
| 2048 | + f = self._state._get(url, {}) | ||
| 2049 | + except Exception as err: | ||
| 2050 | + print(err) | ||
| 2051 | + soup = BeautifulSoup(f, 'lxml') | ||
| 2052 | + lis = soup.find_all("li", {"class": "fbPhotoStarGridElement"}) | ||
| 2053 | + data_list = list() | ||
| 2054 | + for li in lis: | ||
| 2055 | + pic_id = li.attrs.get('data-fbid', None) | ||
| 2056 | + url = li.attrs.get('data-starred-src', None) | ||
| 2057 | + label = li.a.attrs.get('aria-label', None) | ||
| 2058 | + data = { | ||
| 2059 | + 'pic_id': pic_id, | ||
| 2060 | + 'url': url, | ||
| 2061 | + 'label': label | ||
| 2062 | + } | ||
| 2063 | + data_list.append(data) | ||
| 2064 | + res = { | ||
| 2065 | + 'data_list': data_list, | ||
| 2066 | + 'cursor': cursor | ||
| 2067 | + } | ||
| 2068 | + return res | ||
| 2069 | + | ||
| 2070 | + ###############graph接口 start ############## | ||
| 1971 | 2071 | ||
| 1972 | def checkVaild(self): | 2072 | def checkVaild(self): |
| 1973 | try: | 2073 | try: |
-
请 注册 或 登录 后发表评论