[text] A

Viewer

  1. import requests
  2.  
  3. # Login details
  4. username = "Grace+Redding"
  5. password = "Beckett1234"
  6.  
  7. # Login URL and payload
  8. url = "http://www.waitroseconnect.co.uk/names.nsf"
  9. payload = {
  10.     "RedirectTo": "/waitroseconnect/menu.nsf",
  11.     "DBPath": "domcfg.nsf",
  12.     "Server_Name": "www.waitroseconnect.co.uk",
  13.     "Username": username,
  14.     "Password": password
  15. }
  16.  
  17. # Headers
  18. headers = {
  19.     "Content-Type": "text/html"
  20. }
  21.  
  22. # Send login request
  23. response = requests.post(url, data=payload, headers=headers)
  24.  
  25. # Check if login was successful
  26. if response.status_code == 200:
  27.     # Extract Ltpa token from the response cookies
  28.     ltpa_token = response.cookies.get("LtpaToken")
  29.  
  30.     # Use the obtained Ltpa token in subsequent requests
  31.     headers["Cookie"] = f"LtpaToken={ltpa_token}"
  32.  
  33.     # Example: Access a protected resource
  34.     protected_resource_url = "http://www.waitroseconnect.co.uk/waitroseconnect/menu.nsf"
  35.     protected_response = requests.get(protected_resource_url, headers=headers)
  36.  
  37.     # Process the response
  38.     print(protected_response.text)
  39. else:
  40.     print("Login failed:", response.status_code)

Editor

You can edit this paste and save as new:


File Description
  • A
  • Paste Code
  • 06 May-2024
  • 1.11 Kb
You can Share it: