go to login page, put your user name and password , press F12 and record from Network tab
then click on login then copy curl as per the below images, then search for curl to python converter and get the code as per second image, also the code will be attached for you as example
1-
2-
and the code will be like this
import requests
cookies = {
'__utmt_8254f77d54ec9886070127029a0b81da': '1',
'_fbp': 'fb.1.1610535613017.434450469',
'__utmt': '1',
'_ga': 'GA1.2.1008639424.1610535613',
'_gid': 'GA1.2.56271763.1610535614',
'__utma': '28029352.1008639424.1610535613.1610535864.1610535864.1',
'__utmc': '28029352',
'__utmz': '28029352.1610535864.1.1.utmcsr=(direct)^|utmccn=(direct)^|utmcmd=(none)',
'__utmb': '28029352.1.10.1610535864',
'sat_ppv': '84',
}
headers = {
'Connection': 'keep-alive',
'Cache-Control': 'max-age=0',
'Upgrade-Insecure-Requests': '1',
'Origin': 'https://www.eurekalert.org',
'Content-Type': 'application/x-www-form-urlencoded',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'Sec-Fetch-Site': 'same-origin',
'Sec-Fetch-Mode': 'navigate',
'Sec-Fetch-User': '?1',
'Sec-Fetch-Dest': 'document',
'Referer': 'https://www.eurekalert.org/login.php',
'Accept-Language': 'en-US,en;q=0.9',
}
data = {
'frompage': '^',
'username': 'Username',
'password': 'Password'
}
def loginToPage():
# Perform login
response = requests.session().post('https://www.eurekalert.org/login.php', headers=headers, cookies=cookies, data=data)
if response.ok:
print(' logged in successfully')
return True
else:
print('failed to log in')
return False
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…