| 12
 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
 
 | #!/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import requests, sys, urllib
#---------------- Ok pour du mauvais code html; pas propre, quoi :
from bs4 import BeautifulSoup
#
 
url0="http://www.toto.com"
url1="http://www.toto.com/login/loginSubmit"
url2="http://www.toto.com/panelboard"
user_agent={'User-agent': 'Mozilla/5.0'}
resp0=requests.get(url0)
sess0=requests.Session()
print '\n---------------- Écriture du fichier ./resp0.html...'.encode('utf8')
Fichier=open('resp0.html', 'w')
Fichier.write(resp0.content) # text.encode('utf8'))
Fichier.close()
print ('\n\tfirefox -P def2 -no-remote resp0.html &\n')
# print resp0.headers['content-type']
#
#---------------- Ok début page 0 -------------------
#
password='VeryStrong'
pars0={ 'login': 'dva2tlse', 'pass': password }
resp1=sess0.post(url1, data=pars0)
# cook1=resp1.cookies
if(resp1.status_code != 200) :
    print '\n---------------- Boum, resp1.status_code='+resp1.status_code+'\n'
    sys.exit(1)
print '\n---------------- Ok, resp1.url='+resp1.url+', resp1.status_code=%i\n' % (resp1.status_code)
# 
print '\n---------------- Écriture du fichier ./resp1.html...'.encode('utf8')
Fichier=open('resp1.html', 'w')
Fichier.write(resp1.content) # text.encode('utf8'))
Fichier.close()
print ('\n\tfirefox -P def2 -no-remote resp1.html &\n')
# print resp1.headers['content-type']
#
#---------------- page 2 : ------------------
# resp2=sess0.get(url2, cookies=cook1)
resp2=sess0.get(url2)
if(resp2.status_code != 200) :
    print '\n---------------- Boum, resp2.status_code='+resp2.status_code+'\n'
    sys.exit(1)
print '\n---------------- Ok, resp2.url='+resp2.url+', resp2.status_code=%i\n' % (resp2.status_code)
# 
print '\n---------------- Écriture du fichier ./resp2.html...'.encode('utf8')
Fichier=open('resp2.html', 'w')
Fichier.write(resp2.content) # text.encode('utf8'))
Fichier.close()
print ('\n\tfirefox -P def2 -no-remote resp2.html &\n')
# print resp2.headers['content-type']
#
# python ./S.py | 
Partager