-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession_auth_feeds.py
More file actions
executable file
·51 lines (40 loc) · 1.49 KB
/
session_auth_feeds.py
File metadata and controls
executable file
·51 lines (40 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import urllib2
import cookielib
import pickle
from urllib import urlencode
PASSWORD = "********"
def get_feed(url, cookie_pickle):
cookie_jar = cookielib.CookieJar()
for cookie in pickle.loads(cookie_pickle):
cookie_jar.set_cookie(cookie)
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie_jar))
feed = opener.open(url)
feed_string = feed.read()
feed.close()
return feed_string
def get_cookies(url, formdata):
cookie_jar = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie_jar))
feed = opener.open(url, formdata)
feed.close()
return pickle.dumps([c for c in cookie_jar])
pop_data = urlencode({'edit[name]': 'admin',
'edit[pass]': PASSWORD,
'op': 'Log in'
})
login_url = 'http://www.southbend.peopleofpraise.org/user/login'
feed_url = 'http://www.southbend.peopleofpraise.org/node/feed'
# Get cookies
cookies = get_cookies(login_url, pop_data)
# Get feed
feed = get_feed(feed_url, cookies)
# For each feed, need:
# * login_url
# * feed_url
# * where to put un and pwd in form data
# Need to assemble cookie. Find login form. Then submit post with un/pwd.
# User types in page to login
# server grabs that page, alters form action (action = "/capture/?action=%s" % action)
# User types in info and submit.
# Server captures, then submits, either saving info or just saving cookie
# Server could also remember how to submit so we don't have to go through this process again.