Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikibooksThe Free Textbook Project
Search

Python 3: working with files and digital assets/File/Download

From Wikibooks, open books for an open world
<Python 3: working with files and digital assets

Downloading Files

[edit |edit source]

Installation of packages

[edit |edit source]

In Jupyter

[edit |edit source]
%pipinstallrequests%pipinstallpillow

In the command terminal

[edit |edit source]

If you're using the command terminal from your operating system. You can download the required packages by writing the commands:

pipinstallrequestspipinstallpillow


Python Script

[edit |edit source]
fromrequestsimportgetashttp_get_requestsfromPILimportImagefromioimportBytesIOurl_to_image:str='https://upload.wikimedia.org/wikipedia/commons/thumb/3/30/Stepper_Motor%2C_Model_17HS4401N%2C_4.jpg/1024px-Stepper_Motor%2C_Model_17HS4401N%2C_4.jpg'headers={'User-Agent':'Download tutorial([link]; [email])'}response=http_get_requests(url_to_image,headers=headers)
content_type:str=response.headers['content-type']content_length:int=int(response.headers['content-length'])# Desired location to save the filesave_at:str='/mnt/c/Users/Kentv/Desktop/test/test.jpg'
withImage.open(BytesIO(response.content))asimage:image.save(save_at)
Retrieved from "https://en.wikibooks.org/w/index.php?title=Python_3:_working_with_files_and_digital_assets/File/Download&oldid=4308843"
Category:

[8]ページ先頭

©2009-2025 Movatter.jp