Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed some login issues and others #646

Open
wants to merge 7 commits into
base: v1
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[fb_dtsg] patch
  • Loading branch information
MS-Jahan committed Jul 17, 2021
commit 6e23ca664450af26d193328b677e1f3a0b15ba92
49 changes: 35 additions & 14 deletions fbchat/_state.py
Original file line number Diff line number Diff line change
@@ -186,23 +186,44 @@ def from_session(cls, session):
r = session.get(_util.prefix_url("/"))
soup = find_input_fields(r.text)

fb_dtsg_element = soup.find("input", {"name": "fb_dtsg"})
if fb_dtsg_element:
fb_dtsg = fb_dtsg_element["value"]
else:
fb_dtsg = ''

if fb_dtsg == None or fb_dtsg == "":
FB_DTSG_REGEX = re.compile(r'"[a-zA-Z0-9-_:]+:+[a-zA-Z0-9-_:]*"')
fb_dtsg = FB_DTSG_REGEX.search(r.text).group(0)
fb_dtsg = fb_dtsg.replace('"', "")
fb_dtsg = fb_dtsg.replace("'", '')
# print("\n\n[latest] fb_dtsg:\n")
# print(fb_dtsg)


if fb_dtsg == None or fb_dtsg == "":
fb_dtsg_element = soup.find("input", {"name": "fb_dtsg"})
print("\n\n[1]fb_dtsg_element:\n")
print(fb_dtsg_element)
if fb_dtsg_element:
fb_dtsg = fb_dtsg_element["value"]
# print("\n\n[1.1]fb_dtsg_element:\n")
# print(fb_dtsg)

if fb_dtsg == None or fb_dtsg == "":
# Fall back to searching with a regex
fb_dtsg = ''
fb_dtsg = FB_DTSG_REGEX.search(r.text).group(1)

if fb_dtsg == "":
FB_DTSG_REGEX = re.compile(r'"name":"fb_dtsg","value":"(.*?)"')
try:
fb_dtsg = FB_DTSG_REGEX.search(r.text).group(1)

if fb_dtsg == '':
FB_DTSG_REGEX = re.compile(r'"[a-zA-Z0-9_.-]*:[a-zA-Z0-9_.-]*"\)') # I'm not good at regex
fb_dtsg = FB_DTSG_REGEX.search(r.text).group(0)
fb_dtsg = fb_dtsg.replace(")", "")
fb_dtsg = fb_dtsg.replace('"', '')
# print("\n\n[2]fb_dtsg_element:\n")
# print(fb_dtsg)
except:
pass


if fb_dtsg == None or fb_dtsg == "":
FB_DTSG_REGEX = re.compile(r'"[a-zA-Z0-9_.-]*:[a-zA-Z0-9_.-]*"\)')
fb_dtsg = FB_DTSG_REGEX.search(r.text).group(0)
fb_dtsg = fb_dtsg.replace(")", "")
fb_dtsg = fb_dtsg.replace('"', '')
# print("\n\n[3]fb_dtsg_element:\n")
# print(fb_dtsg)

revision = int(r.text.split('"client_revision":')[1].split(",", 1)[0])