Created
April 2, 2018 17:57
-
-
Save raninho/a62ec545c85fdca7056b7f5e93f00d1a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
from time import sleep | |
from random import randint | |
from datetime import datetime | |
import lxml.html | |
import requests | |
URL = "http://saber.pb.gov.br/users/sign_in" | |
USER = "[email protected]" | |
PWD = "senha" | |
def getCookiesAndToken(): | |
r = requests.get(URL) | |
html = lxml.html.fromstring(r.content) | |
token = html.find(".//input[@name='authenticity_token']").value | |
return r.cookies, token | |
def doAuth(): | |
cookies, token = getCookiesAndToken() | |
headers = {"Content-Type":"application/x-www-form-urlencoded","User-Agent":"curl/7.54.0"} | |
data = {'user[email]': USER, 'user[password]': PWD, 'user[remember_me]': "0", 'timeout_path': '', 'utf8': '%E2%9C%93', 'authenticity_token': token} | |
r = requests.post(URL, data=data, cookies=cookies, headers=headers) | |
print(r.status_code) | |
print(r.content) | |
if __name__ == "__main__": | |
doAuth() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment