Skip to content

Instantly share code, notes, and snippets.

@ericsk
Created June 5, 2009 02:46
Show Gist options
  • Save ericsk/124010 to your computer and use it in GitHub Desktop.
Save ericsk/124010 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys
import os
import urllib
import urllib2
import re
def main():
url = sys.argv[1]
pat = url.split('/')[-1].split('&')
userid = pat[0]
folder = pat[1].split('=')[1]
path = 'yam/%s/%s' % (userid, folder)
try:
os.makedirs(path)
except:
pass
i = 1
while True:
cookies = urllib2.HTTPCookieProcessor()
opener = urllib2.build_opener(cookies)
req = urllib2.Request(url=url + '&page=%d&limit=20' % i,
headers={},
data=urllib.urlencode({
'password': folder
}))
resp = opener.open(req)
content = resp.readlines()
valid = False
for line in content:
mat = re.findall('<img src=\"(.*?)\".*>', line)
if mat:
link = mat[0]
if link.find('t_') != -1 and link.find('.jpg') != -1:
valid = True
orig_link = link.replace('t_', '')
f = open('%s/%s' % (path, orig_link.split('/')[-1]), 'w')
req = urllib2.Request(orig_link)
req.add_header('User-Agent', 'Mozilla 5.0')
req.add_header('Referer', url)
data = urllib2.urlopen(req)
f.write(data.read())
f.close()
print 'Fetched: %s.' % orig_link
if not valid:
break
else:
i += 1
print 'Pictures are stored in %s' % path
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment