[2020-09-28]

Python Requests

ses = requests.Session()

Headers

ses.headers.update({
})

Copy cookies from Selenium

ses.cookies.clear()
for cookie in driver.get_cookies():
rc = requests.cookies.create_cookie(domain=cookie['domain'], name=cookie['name'], value=cookie['value'])
ses.cookies.set_cookie(rc)

Download a file

file_url: str
dest_path: str
with tempfile.NamedTemporaryFile() as fp:
with ses.get(file_url, stream=True) as r:
r.raise_for_status()
for chunk in r.iter_content(chunk_size=8192):
fp.write(chunk)
fp.flush()
shutil.copy(fp.name, dest_path)