Laden Sie eine große Datei von der URL mit Python herunterPython

Python-Programme
Anonymous
 Laden Sie eine große Datei von der URL mit Python herunter

Post by Anonymous »

Ich habe die Aufgabe, um 16K+ (maximale Größe von 1 GB) von der angegebenen URL auf den Ort herunterzuladen. Dateien haben einen unterschiedlichen Format wie PDF, PPT, DOC, Docx, ZIP, JPG, ISO usw.
So haben sie unterhalb des Code -Stücks geschrieben, was < /p>

Downloads Datei einige Male und einige Male nur 26KB -Datei nur heruntergeladen wurde. Host "< /li>
< /ol>

Code: Select all

def download_file(s):
for row in sheet.iter_rows(min_row=2):
try:
url = row[6].value #reading from excel
# Send GET request to the URL
response = s.get(url)
if response.status_code == 200:
with open(save_path, 'wb') as file:
file.write(response.content)
except Exception as e:
print(f"Error: {e}")

if __name__ == "__main__":
with requests.session() as s:
res = s.post(login_url, data=login_data)
download_file(s)
< /code>
ausprobiert einen alternativen Ansatz mithilfe von Shutil und Herunterladen in Stücken. Trotzdem wird das [url=viewtopic.php?t=19220]Problem[/url] beobachtet.import shutil
with requests.get(url, stream=True) as r:
with open(local_filename, 'wb') as f:
shutil.copyfileobj(r.raw, f)
< /code>
response = requests.get(url, stream=True)
with open(book_name, 'wb') as f:
for chunk in response.iter_content(1024 * 1024 * 2):
f.write(chunk)

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post