import re
import requests
from datetime import datetime
link = 'https://www.instagram.com/accounts/login/'
login_url = 'https://www.instagram.com/accounts/login/ajax/'
username = 'sem______________________'
password = 'Kolther2201!'
def sessionID():
time = int(datetime.now().timestamp())
payload = {
'username': f'{username}',
'enc_password': f'#PWD_INSTAGRAM_BROWSER:0:{time}:{password}',
'queryParams': {},
'optIntoOneTap': 'false'
}
with requests.Session() as s:
r = s.get(link)
csrf = re.findall(r"csrf_token\":\"(.*?)\"",r.text)[0]
r = s.post(login_url,data=payload,headers={
"User-Agent": "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36",
"X-Requested-With": "XMLHttpRequest",
"Referer": "https://www.instagram.com/accounts/login/",
"x-csrftoken":csrf
})
cookies = str(s.cookies)
# print(cookies.split('sessionid', 1))
print(cookies)
sessionID()
Hey I'm trying to just print out the sessionid from this output:
<RequestsCookieJar[<Cookie csrftoken=XXX for .instagram.com/>, <Cookie ds_user_id=XXX for .instagram.com/>, <Cookie ig_did=XXX for .instagram.com/>, <Cookie mid=XXX for .instagram.com/>, <Cookie rur="XXX" for .instagram.com/>, <Cookie sessionid=XXX for .instagram.com/>]>
What is the easiest way to go about this? I'm uncertain if the length of the sessionid will always be the same.