by
3 5
0
3
280
0
Top 10% !
Popular
Specified
Created
Modified Oct 10, 2017

Published on:

No tags for this snippet yet.
LanguagePython
SourceGitHub
SourceMyGists

Python Selenium get cookie value

Python Selenium get cookie value: 
scrape.py
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/3509468/Python-Selenium-get-cookie-value?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
import time from selenium import webdriver driver = webdriver.Chrome('./chromedriver') driver.get('https://ui.lkqd.com/login') assert 'LKQD' in driver.title time.sleep(2) username_field = driver.find_element_by_name('username') username_field.send_keys('myusername') password_field = driver.find_element_by_name('password') password_field.send_keys('mypassword') submit_button = driver.find_elements_by_xpath("//*[contains(text(), 'Sign In')]")[0] submit_button.click() time.sleep(2) cookies_list = driver.get_cookies() cookies_dict = {} for cookie in cookies_list: cookies_dict[cookie['name']] = cookie['value'] session_id = cookies_dict.get('session') print(session_id) driver.quit()
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus