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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
import cookielib, urllib, urllib2
import os.path
import sys
COOKIEFILE = 'cookies.lwp'
cj = None
user = '06XXXXXXXX'
passw = 'mon_pass'
urlopen = urllib2.urlopen
Request = urllib2.Request
cj = cookielib.LWPCookieJar()
if os.path.isfile(COOKIEFILE):
cj.load(COOKIEFILE)
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
urllib2.install_opener(opener)
mon_url = 'http://smsmms1.orange.fr/C/Sms/sms_write.php'
values = {"credential" : str(user),
"pwd" : str(passw),
"save_user": "false",
"save_pwd" : "false",
"save_TC" : "true",
"action" : "valider",
"usertype" : "",
"service" : "",
"url" : "http://www.orange.fr",
"case" : "",
"origin" : "", }
txdata = urllib.urlencode(values)
#txheaders = {'User-agent' : 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'}
txheaders = { 'Referer' : 'http://id.orange.fr/auth_user/template/auth0user/htm/vide.html','Content-Type':'application/x-www-form-urlencoded'}
try:
req = Request(mon_url, txdata, txheaders)
handle = urlopen(req)
# Ecriture :
f = open("orange.html", "w")
f.write(handle.read())
f.close()
# Lecture :
f = open("orange.html", "r")
var="Non la bonne page n'a pas été trouvée!"
for ligne in f:
mot_recherche="credential"
if mot_recherche in ligne:
var="--- Oui la bonne page est affichée."
print var
print
f.close()
except IOError, e:
print '--- ERREUR'
sys.exit()
else:
print handle.headers
print '--- Voici les cookies:'
for index, cookie in enumerate(cj):
print index, ' : ', cookie
cj.save(COOKIEFILE) |
Partager