-
-
Save naspeh/bc258429fee09f4d7c32 to your computer and use it in GitHub Desktop.
dimetris-hack.py
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
''' | |
Need install mechanize:: | |
easy_install mechanize | |
''' | |
import re | |
import mechanize | |
cookies = mechanize.CookieJar() | |
br = mechanize.build_opener(mechanize.HTTPCookieProcessor(cookies)) | |
br.addheaders = [("User-agent", "Mozilla/5.0 (compatible; MyProgram/0.1)"),] | |
count = 10 | |
user = 'nayavu' | |
host = 'http://dimetris.ru' | |
main_url = '/flowers/new/%s' % user | |
item_url = '/flower_new/%s/' % user | |
def get_photos(page_url): | |
rv = br.open(host + page_url).read() | |
photos = re.findall(r'%s.*?\/\d+' % re.escape(item_url), rv) | |
return photos or [] | |
def get_photos_by_pages(): | |
rv = br.open(host + main_url).read() | |
pages = set(re.findall(r'%s\?page=\d+' % re.escape(main_url), rv)) | |
photos = [] | |
for page in pages: | |
photos += get_photos(page) | |
return photos | |
def go_to_photos(photos): | |
br = mechanize.Browser() | |
for photo in photos: | |
print photo | |
br.open(host + photo) | |
photos = get_photos_by_pages() | |
for i in xrange(count): | |
print '%s>>>' % (i + 1) | |
go_to_photos(photos) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment