Line | |
---|
1 |
|
---|
2 |
|
---|
3 | import json
|
---|
4 | import re
|
---|
5 | import mechanize
|
---|
6 | import sys
|
---|
7 | import pprint
|
---|
8 |
|
---|
9 | cj = mechanize.LWPCookieJar()
|
---|
10 | cj.load("mycookies.txt",ignore_discard=True, ignore_expires=True)
|
---|
11 | #pprint.pprint(cj._cookies)
|
---|
12 |
|
---|
13 | br = mechanize.Browser()
|
---|
14 | br.set_cookiejar(cj)
|
---|
15 |
|
---|
16 | #br.open('https://login.facebook.com/login.php')
|
---|
17 | #br.select_form(nr=0)
|
---|
18 | #br["email"] = "rickvanderzwet@gmail.com"
|
---|
19 | #br["pass"] = "PASSWORD"
|
---|
20 | #response1 = br.submit()
|
---|
21 | #cj.save("mycookies.txt",ignore_discard=True, ignore_expires=True)
|
---|
22 | #pprint.pprint(cj._cookies)
|
---|
23 |
|
---|
24 | #response2 = br.open('http://www.facebook.com/ajax/intent.php?filter=lf&__a=1')
|
---|
25 |
|
---|
26 | #f = open('json.foo', 'w')
|
---|
27 | #f.write(response2.read())
|
---|
28 | #f.close()
|
---|
29 | #json.loads(response2.read())
|
---|
30 |
|
---|
31 | f = open('json.foo', 'r')
|
---|
32 | foo = f.read()
|
---|
33 | foo = foo[9:]
|
---|
34 | #pprint.pprint(foo)
|
---|
35 | obj = json.loads(foo)
|
---|
36 |
|
---|
37 | from xml.dom.minidom import parse, parseString
|
---|
38 | s = obj["payload"]["html"]
|
---|
39 | s = s.encode("utf-8")
|
---|
40 | pprint.pprint(s)
|
---|
41 | import tidy
|
---|
42 | s = tidy.parseString(s, indent=1, tidy_mark=0,doctype="omit").__str__()
|
---|
43 | print s.split()[14:20]
|
---|
44 | doc = parseString(s)
|
---|
45 | print doc.getElementsByTagName("a")
|
---|
46 | # br.select_form(name='login_form')
|
---|
47 | #url = 'https://login.facebook.com/login.php?login_attempt=1'
|
---|
48 | #values = {'email' : 'rickvanderzwet@gmail.com',
|
---|
49 | #'pass' : 'M3nF00b2r!F'}
|
---|
Note:
See
TracBrowser
for help on using the repository browser.