well, you first get to the authenticating page, that is where you put your username & pass ! & then you post them to be authenticated by server which then sends you a session id, which is a cookie.<br><br>now to make the server think you're loged in to the site you have to send him back the cookie.<br>
<br>now to send him the cookie you need the cookielib <br><br>so lets do it right now : <br><br><br>import urllib, urllib2, cookielib<br>user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)' url='http(s)://www.website_to_treat_nicely_and_not_abuse_using_python_scripts.com'<br>
cj=cookielib.LWPCookieJar()<br>values={'username':'python_user', 'passwd':'elephant'}<br><br># let me explain here what values stand for :<br># values will represent every one element of a form that is in the authentication page.<br>
# yes you got it what is between the <form> and </form> & there might be more <br># so you ll have to add them.<br>#<br><br>headers={'User-Agent' : user_agent}<br>opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))<br>
urllib2.install_opener(opener)<br><br># install_opener ? ???? what the hell is this ? ??? <br># well, now every request will take with it the cookie you got from server <br># in other words you will be logged-in to this website from now on<br>
#<br> <br>data=urllib.urlencode(values)<br><br># this is where actin starts (login page here)<br><br>req=urllib2.Request(url, data, headers)<br>response=urllib2.urlopen(req)<br><br><br>url2='http(s)://www.website_to_treat_nicely_and_not_abuse_using_python_scripts.com/second_page'<br>
response2=urllib2.urlopen(url2)<br>response2.read() #you can get the page because urlopen manages the session/cookie for you for free.<br><br>url3='http(s)://www.website_to_treat_nicely_and_not_abuse_using_python_scripts.com/second_page'<br>
response3=urllib2.urlopen(url3)<br>
response3.read() <br><br><br>well, hope this helps<br>