Jan-04-2018, 03:37 AM
(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 callbrowser.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.