From 75d6b89ca4a5cbc23db9cd47ebcd82f6d344fda7 Mon Sep 17 00:00:00 2001 From: PidgeyL Date: Mon, 7 Dec 2015 13:22:20 +0100 Subject: [PATCH 1/3] adding lxml to prevent the error message --- fbchat/client.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fbchat/client.py b/fbchat/client.py index 181dbbf..29d854e 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -81,7 +81,7 @@ class Client(object): if not (self.email and self.password): raise Exception("id and password or config is needed") - soup = bs(self._get("https://m.facebook.com/").text) + soup = bs(self._get("https://m.facebook.com/").text, "lxml") data = dict((elem['name'], elem['value']) for elem in soup.findAll("input") if elem.has_attr('value') and elem.has_attr('name')) data['email'] = self.email data['pass'] = self.password @@ -101,7 +101,7 @@ class Client(object): self.rev = int(r.text.split('"revision":',1)[1].split(",",1)[0]) #self.rev = int(random()*100000) - soup = bs(r.text) + soup = bs(r.text, "lxml") self.fb_dtsg = soup.find("input", {'name':'fb_dtsg'})['value'] for i in self.fb_dtsg: From 981a8d6a721da1d7cd92ad6ec79b31c65dee983f Mon Sep 17 00:00:00 2001 From: PidgeyL Date: Mon, 7 Dec 2015 13:39:01 +0100 Subject: [PATCH 2/3] fix 'potential bug' --- fbchat/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fbchat/client.py b/fbchat/client.py index 29d854e..335db12 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -214,7 +214,7 @@ class Client(object): } r = self._post("https://www.facebook.com/ajax/mercury/threadlist_info.php", data) - if not r.ok: + if not r.ok or len(r.text) == 0: return None j = get_json(r.text) From 767ea2de75b125324f70e0bead7d64cea3a999ac Mon Sep 17 00:00:00 2001 From: PidgeyL Date: Mon, 7 Dec 2015 15:37:22 +0100 Subject: [PATCH 3/3] put url data in the top to increase readability --- fbchat/client.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/fbchat/client.py b/fbchat/client.py index 335db12..f1fa8da 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -19,6 +19,12 @@ from bs4 import BeautifulSoup as bs from .utils import * from .models import * +# URLs +LoginURL ="https://m.facebook.com/login.php?login_attempt=1" +SearchURL ="https://www.facebook.com/ajax/typeahead/search.php" +SendURL ="https://www.facebook.com/ajax/mercury/send_messages.php" +MessagesURL="https://www.facebook.com/ajax/mercury/threadlist_info.php" + class Client(object): """A client for the Facebook Chat (Messenger). @@ -87,7 +93,7 @@ class Client(object): data['pass'] = self.password data['login'] = 'Log In' - r = self._post("https://m.facebook.com/login.php?login_attempt=1", data) + r = self._post(LoginURL, data) self.r = r if 'home' in r.url: @@ -146,7 +152,7 @@ class Client(object): '__rev' : self.rev, } - r = self._get("https://www.facebook.com/ajax/typeahead/search.php", payload) + r = self._get(SearchURL, payload) self.j = j = get_json(r.text) self.r = r @@ -192,9 +198,10 @@ class Client(object): 'message_batch[0][has_attachment]' : False } - r = self._post("https://www.facebook.com/ajax/mercury/send_messages.php", data) + r = self._post(SendURL, data) return r.ok + def getThreadList(self, start, end=None): if not end: end = start + 20 @@ -213,7 +220,7 @@ class Client(object): 'inbox[limit]' : end, } - r = self._post("https://www.facebook.com/ajax/mercury/threadlist_info.php", data) + r = self._post(MessagesURL, data) if not r.ok or len(r.text) == 0: return None