|
...
|
...
|
@@ -22,6 +22,7 @@ from uuid import uuid1 |
|
|
|
import demjson
|
|
|
|
import furl
|
|
|
|
import retrying
|
|
|
|
from bs4 import BeautifulSoup
|
|
|
|
from fbchat import (Client, FBchatException, FBchatUserError, Message, Sticker,
|
|
|
|
ThreadType, _exception, _graphql, _util, log)
|
|
|
|
|
|
...
|
...
|
@@ -32,6 +33,7 @@ from lib.graph import GraphAPIError |
|
|
|
from lib.state import PCState
|
|
|
|
from lib.ttl_cache import lru_cache
|
|
|
|
from utils import _attachment, parse_html
|
|
|
|
from utils.cache import cache
|
|
|
|
|
|
|
|
|
|
|
|
class PostParam(Enum):
|
|
...
|
...
|
@@ -150,14 +152,35 @@ class FacebookClient(Client): |
|
|
|
"to_friend": fbid,
|
|
|
|
"action": "add_friend",
|
|
|
|
"how_found": how_found,
|
|
|
|
"logging_location": 'friends_center',
|
|
|
|
"floc": 'pymk'
|
|
|
|
}
|
|
|
|
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:
|
|
|
|
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:
|
|
...
|
...
|
@@ -1965,9 +1988,86 @@ class FacebookClient(Client): |
|
|
|
"""
|
|
|
|
你的照片
|
|
|
|
"""
|
|
|
|
#如果cursor为None,则请求 https://www.facebook.com/ana.sofia.583671/photos_all 获取到
|
|
|
|
return
|
|
|
|
###############graph接口 start ##############
|
|
|
|
# 如果cursor为None,则请求 https://www.facebook.com/ana.sofia.583671/photos_all 获取到
|
|
|
|
if cursor is None or cursor == '':
|
|
|
|
url = 'https://www.facebook.com/ana.sofia.583671/photos_all'
|
|
|
|
try:
|
|
|
|
session = self._state.session_factory(self.user_obj.user_agent)
|
|
|
|
res = session.get(url, cookies=self._state.get_cookies())
|
|
|
|
html_text = res.text
|
|
|
|
html_text2 = html_text.replace('<!-- ', '').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]
|
|
|
|
print(cursor, num_list)
|
|
|
|
cache.set(f'{self.email}:AllPhotosAppCollectionPagelet', num_list)
|
|
|
|
cache.set(f'{self.email}:AllPhotosAppCollectionPagelet:pagelet_token', pagelet_token)
|
|
|
|
except Exception as err:
|
|
|
|
raise BaseException(f'获取必要参数错误{err}')
|
|
|
|
soup = BeautifulSoup(html_text2, 'lxml')
|
|
|
|
lis = soup.find_all("li", {"class": "fbPhotoStarGridElement"})
|
|
|
|
data_list = list()
|
|
|
|
for li in lis:
|
|
|
|
pic_id = li.attrs.get('data-fbid', None)
|
|
|
|
url = li.attrs.get('data-starred-src', None)
|
|
|
|
label = li.a.attrs.get('aria-label', None)
|
|
|
|
data = {
|
|
|
|
'pic_id': pic_id,
|
|
|
|
'url': url,
|
|
|
|
'label': label
|
|
|
|
}
|
|
|
|
data_list.append(data)
|
|
|
|
res = {
|
|
|
|
'data_list': data_list,
|
|
|
|
'cursor': cursor
|
|
|
|
}
|
|
|
|
return res
|
|
|
|
else:
|
|
|
|
num_list = cache.get(f'{self.email}:AllPhotosAppCollectionPagelet')
|
|
|
|
pagelet_token = cache.get(f'{self.email}:AllPhotosAppCollectionPagelet:pagelet_token')
|
|
|
|
assert num_list is not None, '游标失效,请重新获取首页游标。'
|
|
|
|
get_data = {"collection_token": f"{num_list[0]}:{num_list[1]}:{num_list[2]}",
|
|
|
|
"cursor": cursor,
|
|
|
|
"disablepager": False, "overview": False, "profile_id": num_list[0],
|
|
|
|
"pagelet_token": pagelet_token,
|
|
|
|
"tab_key": "photos", "lst": f"{num_list[0]}:{num_list[0]}:{str(int(time.time()))}",
|
|
|
|
"order": None,
|
|
|
|
"sk": "photos", "importer_state": None}
|
|
|
|
data = {'data': json.dumps(get_data),
|
|
|
|
'fb_dtsg_ag': self._state.fb_dtsg_ag,
|
|
|
|
'dpr': 2,
|
|
|
|
'jazoest': self._state.jazoest
|
|
|
|
}
|
|
|
|
try:
|
|
|
|
url = furl.furl("https://www.facebook.com/ajax/pagelet/generic.php/AllPhotosAppCollectionPagelet").add(
|
|
|
|
data).url
|
|
|
|
f = self._state._get(url, {})
|
|
|
|
except Exception as err:
|
|
|
|
print(err)
|
|
|
|
soup = BeautifulSoup(f, 'lxml')
|
|
|
|
lis = soup.find_all("li", {"class": "fbPhotoStarGridElement"})
|
|
|
|
data_list = list()
|
|
|
|
for li in lis:
|
|
|
|
pic_id = li.attrs.get('data-fbid', None)
|
|
|
|
url = li.attrs.get('data-starred-src', None)
|
|
|
|
label = li.a.attrs.get('aria-label', None)
|
|
|
|
data = {
|
|
|
|
'pic_id': pic_id,
|
|
|
|
'url': url,
|
|
|
|
'label': label
|
|
|
|
}
|
|
|
|
data_list.append(data)
|
|
|
|
res = {
|
|
|
|
'data_list': data_list,
|
|
|
|
'cursor': cursor
|
|
|
|
}
|
|
|
|
return res
|
|
|
|
|
|
|
|
###############graph接口 start ##############
|
|
|
|
|
|
|
|
def checkVaild(self):
|
|
|
|
try:
|
...
|
...
|
|