Python’s Requests Magic
The requests
module is a powerful library that allows you to communicate with websites and web servers. For example, you can download files programmatically, which you would otherwise have to do manually by pressing a button or two.
Downloading files programmatically
import requests
= '?'
url = '?'
local_filename
= requests.get(url)
response
with open(local_filename, 'wb') as file:
file.write(response.content)
="https://www.asc.ohio-state.edu/gan.1/teaching/winter10/"
base_url
for i in range(1,40):
= f'Chapter{i}.pdf'
filename = f'{base_url}/{filename}'
file_url = requests.get(file_url)
response
with open(filename,'wb') as file:
file.write(response.content)
Some things to note:
- You must look at the file url to extract the ‘base url’.
- You must look at the file url to determine the naming convention used for the filename.
- I did not know how many files there were. So, I used 40.