I was tried different approach to get secure and third party cookies. Pasting approach I was tried.
With cookiesjar:
import urllib
import http.cookiejar
url = "https://www.google.com"
cookie_jar = http.cookiejar.CookieJar()
url_opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cookie_jar))
url_opener.open(url)
for cookie in cookie_jar:
print(cookie)
with Requests module:
import requests
r = requests.get('http://www.google.com')
for cookie in r.cookies:
print(cookie.__dict__)
print(cookie.secure)
with PhantomJS:
from selenium import webdriver
cookie_file_path = 'cookie.txt'
args = ['--cookies-file={}'.format(cookie_file_path)]
driver = webdriver.PhantomJS(service_args=args)
driver.get('http://google.com')
driver.get('http://facebook.com')
with open(cookie_file_path) as f:
print(f.read())
with Selenium:
driver = webdriver.Chrome(driver_exe, options=options, desired_capabilities=capabilities)
driver.get('https://google.com')
cookies = driver.get_cookies()
for cookie in cookies:
print(cookie)
Any help or docs related to this would be appriacted.
Thanks :)
CodePudding user response:
Does this give you cookies?
import requests
r = requests.get('http://www.google.com')
print(r.cookies.get_dict())
CodePudding user response:
we can use selenium devtool to extract all the cookies present on the website.
Ref: [1]: https://www.selenium.dev/documentation/webdriver/bidirectional/chrome_devtools/