Created
December 7, 2011 14:43
-
-
Save jorgeguberte/1443051 to your computer and use it in GitHub Desktop.
Download album from Picasa with Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib | |
from xml.dom import minidom | |
''' | |
Opens an xml and parse it | |
Could fetch the xml from Picasa instead of fetching from the disk. | |
''' | |
print 'Fetching xml...' | |
sock = open('xml.xml') | |
xmldoc = minidom.parse(sock).documentElement | |
sock.close() | |
print 'Fetched xml.' | |
'''Parse the xml''' | |
print 'Parsing xml...' | |
dataContainer = [] | |
for entry in xmldoc.getElementsByTagName('media:content'): #media:content is the tag that has the url of the photo | |
if entry.hasAttribute('url'): | |
'''append the url to a list''' | |
dataContainer.append(entry.getAttribute('url')) | |
print 'xml parsed.' | |
'''Iterate over the url list downloading the files and printing info''' | |
i = 1; | |
for entry in dataContainer: | |
print "Downloading %s of %s" %(i, len(dataContainer)) | |
urllib.urlretrieve(entry, "foto%s.jpg"%i) #foto%s is the name i chose...foto1.jpg, foto2.jpg, etc | |
i = i+1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment