Пример, Selenium Grid 4, Node-chrome (в контейнерах)
import os, json, requests
from selenium import webdriver
from selenium.common import exceptions
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec
from webdriver_manager.chrome import ChromeDriverManager
if __name__ == '__main__':
options = webdriver.ChromeOptions()
options.add_argument('user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36')
options.add_argument('--headless')
options.add_argument('--user-data-dir=/app/google-chrome')
# В моем случае, это Selenium Grid 4
driver = webdriver.Remote(command_executor=grid_url, options=options, desired_capabilities={})
driver.get("https://domain.com/some-page-with-cookies")
# Делаем авторизацию, если нужна
# ...
# Забираем куки и удаляем сессию
driver_cookies = driver.get_cookies()
driver.close()
driver.quit()
cookies = {}
for cookie in driver_cookies:
cookies[ cookie['name'] ] = cookie['value']
r = requests.get('https://domain.com/target-url', cookies=cookies)