vitalsource2pdf/vitalsource_scraper/file.py

15 lines
519 B
Python

import requests
def download_file(url, full_output_path, headers):
# NOTE the stream=True parameter below
with requests.get(url, stream=True, headers=headers) as r:
r.raise_for_status()
with open(full_output_path, 'wb') as f:
for chunk in r.iter_content(chunk_size=8192):
# If you have chunk encoded response uncomment if
# and set chunk_size parameter to None.
# if chunk:
f.write(chunk)
return full_output_path