[Python] Automatizzare inserimento dati su pagina web

Marco De Paoli depaolim a gmail.com
Gio 20 Nov 2014 16:21:02 CET


Il 20 novembre 2014 16:11, Gollum1 <gollum1.smeagol1 a gmail.com> ha scritto:
> ok... ho fatto i primi tentativi da console:
>
> r = requests.get('https://10.24.144.13/ucmuser/?logoff=t',
> auth=('mio_login', 'mia_password'))
> Traceback (most recent call last):
>   File "<input>", line 1, in <module>
>   File "D:\My Documents\p977727\Documents\03 -
> Sviluppo\PythonVirtualEnvironment\VE-GestioneTelefono\lib\site-packages\requests\api.py",
> line 60, in get
>     return request('get', url, **kwargs)
>   File "D:\My Documents\p977727\Documents\03 -
> Sviluppo\PythonVirtualEnvironment\VE-GestioneTelefono\lib\site-packages\requests\api.py",
> line 49, in request
>     return session.request(method=method, url=url, **kwargs)
>   File "D:\My Documents\p977727\Documents\03 -
> Sviluppo\PythonVirtualEnvironment\VE-GestioneTelefono\lib\site-packages\requests\sessions.py",
> line 457, in request
>     resp = self.send(prep, **send_kwargs)
>   File "D:\My Documents\p977727\Documents\03 -
> Sviluppo\PythonVirtualEnvironment\VE-GestioneTelefono\lib\site-packages\requests\sessions.py",
> line 569, in send
>     r = adapter.send(request, **kwargs)
>   File "D:\My Documents\p977727\Documents\03 -
> Sviluppo\PythonVirtualEnvironment\VE-GestioneTelefono\lib\site-packages\requests\adapters.py",
> line 420, in send
>     raise SSLError(e, request=request)
> requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED]
> certificate verify failed (_ssl.c:600)
>
> ho provato anche con il put... stesso errore...
>
> questo l'output di chrome sugli headers che transitano quando faccio
> l'autenticazione, vedo che dovrebbe essere passato tutto come post, ma
> forse il mio tentativo è andato a vuoto perchè la richiesta devo
> passarla in post, ma con le due variabili j_username e J_password...
>
> Remote Address:
> 10.24.144.13:443
> Request URL:
> https://10.24.144.13/ucmuser/j_security_check
> Request Method:
> POST
> Status Code:
> 302 Found
> Request Headersview source
>
> Accept:
> text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
> Accept-Encoding:
> gzip, deflate
> Accept-Language:
> it,it-IT;q=0.8,en-US;q=0.6,en;q=0.4
> Cache-Control:
> max-age=0
> Connection:
> keep-alive
> Content-Length:
> 43
> Content-Type:
> application/x-www-form-urlencoded
> Cookie:
> JSESSIONID=63413AB58767E5CF0B39D02EFB036813
> Host:
> 10.24.144.13
> Origin:
> https://10.24.144.13
> Referer:
> https://10.24.144.13/ucmuser/main
> User-Agent:
> Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko)
> Chrome/39.0.2171.65 Safari/537.36
>
> Form Dataview sourceview URL encoded
>
> j_username:
> mio_login
> j_password:
> mia_password
>
> Response Headersview source
>
> Content-Length:
> 0
> Date:
> Thu, 20 Nov 2014 13:27:01 GMT
> Location:
> https://10.24.144.13/ucmuser/main
> Server:

qualcosa del genere?

>>> payload = {'j_username': 'mio_login', 'j_password': 'mia_password'}
>>> r = requests.get("https://10.24.144.13/ucmuser/j_security_check", params=payload)

a quel punto dovrebbe tornarti indietro il cookie di sessione e da
quel momento dovresti poter andare in get sulle varie pagine...


Maggiori informazioni sulla lista Python