Download Beautiful wallpaper from momentum in Python

Source: Internet
Author: User

#! /usr/bin/python# encoding=utf-8 "" "@desc download Beautiful wallpaper in momentum @api https://d3cbihxaqsuq0s.cloudfront.net/@author Tan < [email protected]> "" "Import requestsimport reimport osimport urllibimport xml.dom.minidomdef Download (URL, Path = '): Name = Url.split ('/') [ -1:-2:-1] path = path if path else Os.path.join ('./tmp/', fname if fname els    E name) dirname = os.path.dirname (path) print path if not os.path.exists (dirname): Os.makedirs (dirname) Try:return urllib.urlretrieve (URL, path) except Exception,e:print "Error:", E return falsedef p        Arsexmlfile (name): DOM = xml.dom.minidom.parse (name) List = dom.documentelement if List.hasattribute ("xmlns"): Print "Listbucketresult:%s"% list.getattribute ("xmlns") results = [] # gets all contents contents = List in the collection . getElementsByTagName ("Contents") # Print detailed information for each Content for C in Contents:print "*****content*****" Key = C.getelementsbytagname (' Key ') [0]       #print "Key:%s"% key.childnodes[0].data lastmodified = c.getelementsbytagname (' lastmodified ') [0] #p Rint "LastModified:%s"% lastmodified.childnodes[0].data ETag = c.getelementsbytagname (' ETag ') [0] #print "E Tag:%s "% etag.childnodes[0].data size = c.getelementsbytagname (' size ') [0] #print" size:%s "% Size.childno Des[0].data Storageclass = c.getelementsbytagname (' storageclass ') [0] #print "storageclass:%s"% Storageclas S.childnodes[0].data item = {"Key": Key.childnodes[0].data, "ETag": Etag.childnodes[0].da TA, "size": Size.childnodes[0].data, "lastmodified": Lastmodified.childnodes[0].data, "  Storageclass ": Storageclass.childnodes[0].data} results.append (item) return RESULTSDEF main (): TMP =    './tmp/';        #下载xml path = Os.path.join (tmp, ' contents.xml ') if not download (' https://d3cbihxaqsuq0s.cloudfront.net/', path): Return False #解析xml并下载图片 contents = parsexmlfile (path) If Len (contents): For item in Contents:print            Item if not item[' key '].find ('. jpg '): Continue path = Os.path.join (tmp, item[' key ')     Download (' https://d3cbihxaqsuq0s.cloudfront.net/' + item[' key '], path) return trueif __name__ = = ' __main__ ': Main ()

Download Beautiful wallpaper from momentum in Python

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.