Getting started with Python 002 bulk download images from Web links

Source: Internet
Author: User

We often need to download a lot of favorite pictures on the page, but facing dozens of or even hundreds of pictures, one to save as a must be a bad experience.

We can use the Urllib package to obtain the HTML source code, and then the regular expression to the matching image link into a list, using a for loop to download the list of links in sequence.

ImportReImportUrlliba= Raw_input ("Please input a URL:") s=Urllib.urlopen (a) S2=S.read ()defimage (S2): Reg= R'src= "(. *?\.jpg)" Pic_ext'Compile_reg=Re.compile (reg) ImageList=Re.findall (compile_reg,s2) Temp=0 forXinchimagelist:temp+ = 1urllib.urlretrieve (x,'%s.jpg'%temp) A="OK"    returnaPrintImage (S2)

Urllib Package Reference: Python standard library Urllib

Getting started with Python 002 bulk download images from Web links

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.