Created
August 27, 2020 13:35
-
-
Save cxkoda/a02572c8036a48f471b3836c48394e3f to your computer and use it in GitHub Desktop.
TESS Asteroseismic Science Operations Center (TASOC) Python Login
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
import requests | |
from bs4 import BeautifulSoup | |
with requests.Session() as session: | |
# Get login token | |
response = session.get('https://tasoc.dk') | |
soup = BeautifulSoup(response.text, 'html.parser') | |
tokens = soup.find_all("input", {'name': 'token'}) | |
assert(len(tokens) == 1) | |
token = tokens[0].get('value') | |
# Do login | |
payload = { | |
'username': '[email protected]', | |
'password': 'supersecure', | |
'submit' : 'Login', | |
'remember': 'on', | |
'token': token | |
} | |
response = session.post('https://tasoc.dk/login/login.php', data=payload) | |
# Get page | |
testurl = 'https://tasoc.dk/catalog/264594259' | |
response = session.get(testurl) | |
with open('response.html', 'w') as outfile: | |
outfile.write(response.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
init