import json import re import mechanize import sys import pprint cj = mechanize.LWPCookieJar() cj.load("mycookies.txt",ignore_discard=True, ignore_expires=True) #pprint.pprint(cj._cookies) br = mechanize.Browser() br.set_cookiejar(cj) #br.open('https://login.facebook.com/login.php') #br.select_form(nr=0) #br["email"] = "rickvanderzwet@gmail.com" #br["pass"] = "PASSWORD" #response1 = br.submit() #cj.save("mycookies.txt",ignore_discard=True, ignore_expires=True) #pprint.pprint(cj._cookies) #response2 = br.open('http://www.facebook.com/ajax/intent.php?filter=lf&__a=1') #f = open('json.foo', 'w') #f.write(response2.read()) #f.close() #json.loads(response2.read()) f = open('json.foo', 'r') foo = f.read() foo = foo[9:] #pprint.pprint(foo) obj = json.loads(foo) from xml.dom.minidom import parse, parseString s = obj["payload"]["html"] s = s.encode("utf-8") pprint.pprint(s) import tidy s = tidy.parseString(s, indent=1, tidy_mark=0,doctype="omit").__str__() print s.split()[14:20] doc = parseString(s) print doc.getElementsByTagName("a") # br.select_form(name='login_form') #url = 'https://login.facebook.com/login.php?login_attempt=1' #values = {'email' : 'rickvanderzwet@gmail.com', #'pass' : 'M3nF00b2r!F'}