Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unable to load cookies with Pickle
#5
(Jan-04-2018, 03:05 AM)snippsat Wrote: You seems to do some do some strange stuff like running all in a while loop for interactive interpreter(>>>).
The while loop is not needed as Selenium run continuous until call browser.quit().
Here a example,and i use json because i don't like pickle.
from selenium import webdriver
import json

browser = webdriver.Chrome()
url = 'https://www.google.com/'
browser.get(url)
cookie = browser.get_cookies()
browser.quit()

with open('cookie', 'w') as j_out:
    json.dump(cookie, j_out)
with open('cookie') as j:
    saved_cookie = json.load(j)


#print(saved_cookie) # The whole cookie as a list with dictionaries 
print(saved_cookie[0]['domain'])
print(saved_cookie[0]['httpOnly'])
Output:
.google.no False

In what order do I do all of this? I tried the first method and that worked once, however it is no longer working. I want to try to get this using json, but can you explicitly tell me how to go about creating a cookie? Right now this is what I do:
from selenium import webdriver
import json

browser = webdriver.Chrome()
url = 'https://www.google.com/'
browser.get(url)
# I OPEN ANOTHER TAB AND LOG INTO MY ACCOUNT ON GOOGLE AND ON THAT WEBSITE
cookie = browser.get_cookies()
browser.quit()
# Now I close python and open it again

from selenium import webdriver
import json
browser = webdriver.Chrome()
cookie = browser.get_cookies()
url = 'https://www.google.com/'
with open('cookie', 'w') as j_out:
    json.dump(cookie, j_out)
with open('cookie') as j:
    saved_cookie = json.load(j)
browser.get(url)
However, the cookies do not save. This I know because I am not logged into google.
Reply


Messages In This Thread
Unable to load cookies with Pickle - by HiImNew - Jan-04-2018, 01:30 AM
RE: Unable to load cookies with Pickle - by HiImNew - Jan-04-2018, 02:44 AM
RE: Unable to load cookies with Pickle - by HiImNew - Jan-04-2018, 03:37 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Saving/editing cookies? rhubarbpieguy 0 920 Dec-10-2022, 01:58 PM
Last Post: rhubarbpieguy
  Python cookies vj78 2 3,125 Apr-07-2021, 09:38 AM
Last Post: Naheed
  Catch all cookies from any website Chuky 8 10,489 Aug-20-2019, 04:24 PM
Last Post: snippsat
  python scraping all cookies halberdd 1 4,861 Feb-26-2019, 12:10 PM
Last Post: halberdd
  Flask: Cookies for Saving User Input ? jomonetta 2 3,531 Nov-03-2018, 10:47 AM
Last Post: j.crater
  Inserting multiple cookies using python requests freshtomatoes 0 5,347 Aug-16-2018, 09:25 PM
Last Post: freshtomatoes
  unable to load file using python selenium purnima1 4 6,556 Dec-12-2017, 04:04 PM
Last Post: hshivaraj
  Missing cookies in session with requests sechot 0 6,294 Oct-22-2017, 12:09 PM
Last Post: sechot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020