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
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
import cookielib, urllib, urllib2
import os.path
import sys
COOKIEFILE = 'cookies.lwp' #### le chemin et fichier pour sauvegarder vos cookies
cj = None
#!/usr/bin/python
# -*- coding: utf-8 -*-
import cookielib, urllib, urllib2
import os.path
import sys
COOKIEFILE = 'cookies.lwp'
cj = None
user_credential = 'XXXXXX'
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 = {'user_credential':user_credential}
txdata = urllib.urlencode(values)
txheaders = {'User-agent' : 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'}
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=user_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