title: Exporting Session cookies to JSON format to be imported to Chrome
body: <p>I'm trying to export the cookies from a session, but the format used doesn't suit my needs. I need to import these cookies into a Selenium chrome driver.</p>
  
  <pre><code>import requests
  from bs4 import BeautifulSoup
  
  
  base = "https://amazon.com/ap/signin?ie=UTF8&amp;openid.pape.max_auth_age=0&amp;openid.return_to=https%3A%2F%2Fwww.amazon.com%2F%3Fref_%3Dnav_ya_signin&amp;openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&amp;openid.assoc_handle=usflex&amp;openid.mode=checkid_setup&amp;openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&amp;openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&amp;switch_account=signin&amp;ignoreAuthState=1&amp;disableLoginPrepopulate=1&amp;ref_=ap_sw_aa"
  header = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:71.0) Gecko/20100101 Firefox/71.0", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Language": "en-US,en;q=0.5", "Accept-Encoding": "gzip, deflate", "Origin": "https://amazon.com/ap/signin", "Referer": "https://amazon.com/ap/signin", "Connection": "close"}
  head = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:71.0) Gecko/20100101 Firefox/71.0", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Language": "en-US,en;q=0.5", "Accept-Encoding": "gzip, deflate", "Content-Type": "application/x-www-form-urlencoded", "Origin": "https://amazon.com", "Connection": "close"}
  
  users = {}
  
  session = requests.session()
  response = session.get(base, headers=header)
  soup = BeautifulSoup(response.text, "html.parser")
  
  openid = soup.find('input', {'name':'openid.return_to'})['value']
  prevRID = soup.find('input', {'name':'prevRID'})['value']
  workflowState = soup.find('input', {'name':'workflowState'})['value']
  appActionToken = soup.find('input', {'name':'appActionToken'})['value']
  session_id = session.cookies['session-id']
  
  email = "email"
  pw = "password"
  
  data = {"appActionToken": appActionToken, "appAction": "SIGNIN", "openid.return_to": openid, "prevRID": prevRID,
          "workflowState": workflowState, "email": email, "create":0, "password": pw}
  
  response = session.post("https://amazon.com/ap/signin", data=data, headers=head)
  main_page = session.get("https://www.amazon.com/?ref_=nav_ya_signin&amp;", headers=head)
  
  if "Welcome to Amazon" in main_page.text:
      # export cookies
      print("Exporting cookies..")
  
  
  else:
      # sign in failed.
      print("Fail")
  </code></pre>