A little reptile download jpg image to desktop >>>>>python2.7.x

Source: Internet
Author: User

Import re
import urllib2
headers = {' user-agent ': ' mozilla/5.0 (Windows NT 6.2; WOW64; rv:22.0) gecko/20100101 firefox/22.0 '}
with open (' C:\\users\\yaxin\\desktop\\1.txt ', ' r ') as file:    # Save the Web page source to 1.txt in advance
    data = File.read ()
pattern = Re.compile (r " need = pattern.findall (data)
Count = 0
For i in Need:
    i = i + ' jpg ' #补全网址
    with open (' c:\\users\\yaxin\\desktop\\boot\\%s.jpg '%i[-8:-4], ' WB ') as F: #以网址中后8位到后5位作为文件名
  & nbsp     request = Urllib2. Request (I, headers = headers)
        data_res = Urllib2.urlopen (Request)
      & nbsp Data_b = Data_res.read () #二进制数据
        F.write (data_b)
        count = Coun T + 1
        print ' done     ' + str (count)
print (' Done ') #结束标志

A small reptile download jpg images to desktop >>>>>python2.7.x

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.