Through python I want to post a fb status using the urllib, urllib2, cookielib (without downloading modules). I would successfully log in, but then my code for posting a status would not work. I would inspect the element of the status message box and post box (for m.facebook) and the status message box 'name' is status and the 'value' of the post box is Post but it would not post a status when I would try. How can I make this work?
import urllib2, urllib, cookielib
class Acc:
jar = cookielib.CookieJar()
cookie = urllib2.HTTPCookieProcessor(jar)
opener = urllib2.build_opener(cookie)
def login(self):
try:
params = urllib.urlencode({'email':'user@hotmail.com','pass':'password','login':'Log+In'})
req = urllib2.Request('http://m.facebook.com/login.php?m=m&refsrc=m.facebook.com%2F', params)
res = self.opener.open(req)
html = res.read()
except urllib2.HTTPError, e:
print e.msg
except urllib2.URLError, e:
print e.reason[1]
return False
def fetch(self,url):
req = urllib2.Request(url,None)
res = self.opener.open(req)
return res.read(), res.headers.get("Set-Cookie")
bla = Acc()
bla.login()
webpage, session = bla.fetch("http://m.facebook.com/login.php?m=m&refsrc=m.facebook.com%2F")
if "Logout" in webpage:
print("Logged in cuzzie")
print("Sending Post")
post = urllib.urlencode({'status':'message','Post':'Post'})
a = urllib2.Request("http://m.facebook.com/")
a.add_header("cookie", session)
g = urllib2.urlopen(a, post)
print("Post Sent")