Skip to content

Instantly share code, notes, and snippets.

@pointofpresence
Last active March 31, 2024 18:15
Show Gist options
  • Save pointofpresence/ba21b94ead3e537a2dcc7584b0050a43 to your computer and use it in GitHub Desktop.
Save pointofpresence/ba21b94ead3e537a2dcc7584b0050a43 to your computer and use it in GitHub Desktop.
Python: Авторизация с использованием cookies
import requests
LOGIN_URL = 'https://examplenotarealpage.com'
headers = {
'accept': 'text/html,application/xhtml+xml,application/xml',
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36'
}
response = requests.get(LOGIN_URL, headers=headers, verify=False)
headers['cookie'] = '; '.join([x.name + '=' + x.value for x in response.cookies])
headers['content-type'] = 'application/x-www-form-urlencoded'
payload = {
'username': 'user_name',
'password': 'randompass123'
}
response = requests.post(LOGIN_URL, data=payload, headers=headers, verify=False)
headers['cookie'] = '; '.join([x.name + '=' + x.value for x in response.cookies])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment