Python Download Pictures Simple tutorial

Source: Internet
Author: User

through the Urlretrieve method
Import OS
#导入os包, the module can be installed with the PIP installl command without the module
From urllib.request import Urlretrieve
#导入urllib模块
Image_url= "Https://bpic.588ku.com/element_pic/00/16/10/21580951c08d0a9.jpg!/fw/208/quality/90/unsharp/true/compress/true"
#设置一个图片的url, whatever.
Os.makedirs ('./img/', exist_ok=true)
#通过os在当前的工作路径下制作一个img目录, you don't have to say that.
Urlretrieve (Image_url, './img/image1.png ')
#通过urllib的urlretrieve方法使得把图片下载保存到指定的目录
Print (' OK ')
#确认是否执行成功
get through the requests method
Import OS
Import requests
#导入os包, the module can be installed with the PIP installl command without the module
From urllib.request import Urlretrieve
#导入urllib模块
Image_url = "https://bpic.588ku.com/element_pic/00/16/10/21580951c08d0a9.jpg!/fw/208/quality/90/unsharp/true/ Compress/true "
#设置一个图片的url, whatever.
R = Requests.get (Image_url, Stream=true)
With open ('./img/image3.png ', ' WB ') as F:
For chunk in R.iter_content (chunk_size=32):
F.write (Chunk)
Print (' OK ')

Python Download Pictures Simple tutorial

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.