Answer the question
In order to leave comments, you need to log in
How to download a file from the link /download.php?id=1241?
I need to parse links to site files and download them. I decided to download 1 file from 1 link.
Here is the code:
import requests
session=requests.session()
headers={"User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0","Accept":"text/ html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"}
r=session.get(url,headers=headers)
soup=BeautifulSoup(r.text,'lxml')
url = ' http://Website/engine/download.php?id=1241 '
f=open(r'file.pptx',"wb")
ufr=session.get(url,headers=headers)
print(ufr)
f .write(ufr.content)
f.close()
As a result I see a presentation file in the folder,
Answer the question
In order to leave comments, you need to log in
Try the example from here: https://stackoverflow.com/questions/16694907/downl...
def download_file(url):
local_filename = url.split('/')[-1]
# NOTE the stream=True parameter below
with requests.get(url, stream=True) as r:
with open(local_filename, 'wb') as f:
for chunk in r.iter_content(chunk_size=8192):
if chunk: # filter out keep-alive new chunks
f.write(chunk)
# f.flush()
return local_filename
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question