|
@@ -5,6 +5,7 @@ |
|
@@ -5,6 +5,7 @@ |
|
5
|
# @File : facebook.py
|
5
|
# @File : facebook.py
|
|
6
|
# @Software: PyCharm
|
6
|
# @Software: PyCharm
|
|
7
|
import base64
|
7
|
import base64
|
|
|
|
8
|
+import itertools
|
|
8
|
import json
|
9
|
import json
|
|
9
|
import os
|
10
|
import os
|
|
10
|
import random
|
11
|
import random
|
|
@@ -12,6 +13,7 @@ import re |
|
@@ -12,6 +13,7 @@ import re |
|
12
|
import time
|
13
|
import time
|
|
13
|
from enum import Enum
|
14
|
from enum import Enum
|
|
14
|
|
15
|
|
|
|
|
16
|
+import demjson
|
|
15
|
import furl
|
17
|
import furl
|
|
16
|
from fbchat import Client, ThreadType, Message, Sticker, FBchatUserError, _exception, log, _util
|
18
|
from fbchat import Client, ThreadType, Message, Sticker, FBchatUserError, _exception, log, _util
|
|
17
|
from fbchat._state import State, session_factory, is_home
|
19
|
from fbchat._state import State, session_factory, is_home
|
|
@@ -90,10 +92,22 @@ class PCState(State): |
|
@@ -90,10 +92,22 @@ class PCState(State): |
|
90
|
else:
|
92
|
else:
|
|
91
|
id = name = url = image = None
|
93
|
id = name = url = image = None
|
|
92
|
|
94
|
|
|
|
|
95
|
+ fb_dtsg = None
|
|
|
|
96
|
+ fb_dtsg_ag = None
|
|
|
|
97
|
+ jazoest = None
|
|
93
|
try:
|
98
|
try:
|
|
94
|
- fb_dtsg = re.compile(r'name="fb_dtsg" value="(.*?)"').search(r.text).group(1)
|
99
|
+ rec = re.compile(r'\["DTSGInitData",\[\],(\{.*?\}),\d+\]')
|
|
|
|
100
|
+ initdata = rec.search(r.text).group(1)
|
|
|
|
101
|
+ initdata = json.loads(initdata)
|
|
|
|
102
|
+ fb_dtsg = initdata['token']
|
|
|
|
103
|
+ fb_dtsg_ag = initdata['async_get_token']
|
|
95
|
except:
|
104
|
except:
|
|
96
|
- fb_dtsg = None
|
105
|
+ pass
|
|
|
|
106
|
+
|
|
|
|
107
|
+ try:
|
|
|
|
108
|
+ jazoest = re.search(r'name="jazoest" value="(\d+)"', r.text).group(1)
|
|
|
|
109
|
+ except:
|
|
|
|
110
|
+ pass
|
|
97
|
|
111
|
|
|
98
|
revision = int(r.text.split('"client_revision":', 1)[1].split(",", 1)[0])
|
112
|
revision = int(r.text.split('"client_revision":', 1)[1].split(",", 1)[0])
|
|
99
|
|
113
|
|
|
@@ -105,7 +119,7 @@ class PCState(State): |
|
@@ -105,7 +119,7 @@ class PCState(State): |
|
105
|
revision=revision,
|
119
|
revision=revision,
|
|
106
|
session=session,
|
120
|
session=session,
|
|
107
|
logout_h=logout_h,
|
121
|
logout_h=logout_h,
|
|
108
|
- counter=0
|
122
|
+ counter=0,
|
|
109
|
)
|
123
|
)
|
|
110
|
|
124
|
|
|
111
|
self.id = id
|
125
|
self.id = id
|
|
@@ -113,6 +127,8 @@ class PCState(State): |
|
@@ -113,6 +127,8 @@ class PCState(State): |
|
113
|
self.page_url = url
|
127
|
self.page_url = url
|
|
114
|
self.imageurl = image
|
128
|
self.imageurl = image
|
|
115
|
self._online = is_online
|
129
|
self._online = is_online
|
|
|
|
130
|
+ self.fb_dtsg_ag = fb_dtsg_ag
|
|
|
|
131
|
+ self.jazoest = jazoest
|
|
116
|
return self
|
132
|
return self
|
|
117
|
|
133
|
|
|
118
|
|
134
|
|
|
@@ -718,17 +734,34 @@ class FacebookClient(Client): |
|
@@ -718,17 +734,34 @@ class FacebookClient(Client): |
|
718
|
def get_user_agent(self):
|
734
|
def get_user_agent(self):
|
|
719
|
return self._state._session.headers.get('User-Agent', random.choice(_util.USER_AGENTS))
|
735
|
return self._state._session.headers.get('User-Agent', random.choice(_util.USER_AGENTS))
|
|
720
|
|
736
|
|
|
721
|
- def searchForUserByFilter(self, name=None, city=None):
|
|
|
|
722
|
- url = 'https://www.facebook.com/search/top/'
|
|
|
|
723
|
- data = {'q': 'angel',
|
|
|
|
724
|
- 'ref': 'side_filter',
|
|
|
|
725
|
- 'epa': 'FILTERS',
|
|
|
|
726
|
- 'filters': 'eyJycF9sb2NhdGlvbiI6IntcIm5hbWVcIjpcImxvY2F0aW9uXCIsXCJhcmdzXCI6XCIxMDYyNjI4ODI3NDU2OThcIn0ifQ==',
|
|
|
|
727
|
- 'ajaxpipe': '1',
|
|
|
|
728
|
- 'ajaxpipe_token': 'AXjhI9q4VDQji6Ox',
|
|
|
|
729
|
- 'quickling[version]': '1001720869;0;'
|
737
|
+ def searchForUserByFilter(self, ext_data=None):
|
|
|
|
738
|
+ if not ext_data:
|
|
|
|
739
|
+ r = self._state._session.get(
|
|
|
|
740
|
+ 'https://www.facebook.com/search/people/?q=%E5%B1%B1%E4%B8%8B&epa=FILTERS&filters=eyJjaXR5Ijoie1wibmFtZVwiOlwidXNlcnNfbG9jYXRpb25cIixcImFyZ3NcIjpcIjEwNjUxNDAwNjA1MzI1MFwifSJ9')
|
|
|
|
741
|
+ fbid = parse_html.get_all_raw_id(r.text)
|
|
|
|
742
|
+
|
|
|
|
743
|
+ global_data = re.findall(r'globalData:(\{.*?display_params.*?\}),prefetchPixels', r.text)[0]
|
|
|
|
744
|
+ data = demjson.decode(global_data)
|
|
|
|
745
|
+ complete = re.findall('"pageletComplete",\[\],\[(.*?)\]', r.text)[0]
|
|
|
|
746
|
+ data.update(demjson.decode(complete))
|
|
|
|
747
|
+ return {'fbid_list': fbid, 'ext_data': data}
|
|
|
|
748
|
+ else:
|
|
|
|
749
|
+ data = {'data': demjson.encode(ext_data), 'fb_dtsg_ag': self._state.fb_dtsg_ag}
|
|
|
|
750
|
+ res = self._state._get('https://www.facebook.com/ajax/pagelet/generic.php/BrowseScrollingSetPagelet', data)
|
|
|
|
751
|
+ ext_data.pop('page_number')
|
|
|
|
752
|
+ try:
|
|
|
|
753
|
+ for x in res.get('jsmods').get('require'):
|
|
|
|
754
|
+ if len(x) == 4 and x[1] == 'pageletComplete':
|
|
|
|
755
|
+ ext_data.update(x[3][0])
|
|
|
|
756
|
+ break
|
|
|
|
757
|
+ except:
|
|
|
|
758
|
+ pass
|
|
|
|
759
|
+
|
|
|
|
760
|
+ fbid = parse_html.get_all_raw_id(res['payload'])
|
|
|
|
761
|
+ if fbid and 'page_number' not in ext_data:
|
|
|
|
762
|
+ ext_data = None
|
|
|
|
763
|
+ # 无更多了
|
|
|
|
764
|
+ return {
|
|
|
|
765
|
+ 'fbid_list': fbid,
|
|
|
|
766
|
+ 'ext_data': ext_data,
|
|
730
|
} |
767
|
} |
|
731
|
- # f = furl.furl(url).add(data)
|
|
|
|
732
|
- # print(f.url)
|
|
|
|
733
|
- res=self._state._get('https://www.facebook.com/search/people/?q=angel&epa=FILTERS&filters=eyJjaXR5Ijoie1wibmFtZVwiOlwidXNlcnNfbG9jYXRpb25cIixcImFyZ3NcIjpcIjEwNjI2Mjg4Mjc0NTY5OFwifSJ9&ref=side_filter',{})
|
|
|
|
734
|
- print(res) |
|
|