ich bin in der Lage mich mittels Modul requests auf einem Portal anzumelden. Aber wie kann ich mich wieder erfolgreich abmelden?
Code: Alles auswählen
import requests
import sys
import time
# Fill in your details here to be posted to the login form.
payload = {
'username': 'test_user',
'password': 'test_password'
}
url = 'http://www.metalflirt.de/community/login'
# Use 'with' to ensure the session context is closed after use.
# Session used to handle cookies
with requests.Session() as c:
# here is the login URL, and the data we want to submit
c.post(url, data=payload)
# An authorised request.
# test it by accessing hidden page
r = c.get('http://www.metalflirt.de/community/moshpit')
# Here it will tests the login, to make sure
# we already logged in into the system
log_status = payload["username"] in r.content
print log_status
print 'cookies befor clearing', requests.utils.dict_from_cookiejar(c.cookies)
c.cookies.clear()
print 'cookies after clearing', requests.utils.dict_from_cookiejar(c.cookies)
if log_status == True:
time.sleep(5)
c.get('http://www.metalflirt.de/community/logout')
print r.content
else:
print r.content