0

Would it be possible to automate the process of logging into a site within the firefox browser, copy and store the cookie, place it in a DB table?

Scratching my head with this one.

jarlh
  • 35,821
  • 8
  • 33
  • 49
user3296793
  • 266
  • 1
  • 12
  • you can use `requests`/`urllib` with `BeautifulSoup`/`lxml` and it doesn't need browser. Or use `Selenium` to control web browser - ie. Firefox. First method can work faster but it can't run JavaScript. Second uses real web browser so it is slower but web browser runs JavaScript. – furas May 03 '19 at 09:01

1 Answers1

1

A simple way to achieve this is through browser automation.

from selenium import webdriver

driver = webdriver.Firefox(executable_path='{/path/to/geckodriver}')
driver.get("http://google.com")
cookies = driver.get_cookies()

Note: Download geckodriver compatiable to your firefox.

Edit: Completly overlooked the fact that python's requests module has a cookies attribute. This would be quicker compared to browser automation.

import requests

resp = requests.get("http://google.com")
cookies = resp.cookies._cookies
kartheek7895
  • 301
  • 1
  • 11