Skip to content

Instantly share code, notes, and snippets.

@BIGBALLON
Created April 17, 2018 15:07
Show Gist options
  • Save BIGBALLON/c06da67e3625c2cb12793b158ff81341 to your computer and use it in GitHub Desktop.
Save BIGBALLON/c06da67e3625c2cb12793b158ff81341 to your computer and use it in GitHub Desktop.
tgram stickers download script
# *-* coding: UTF-8 *-*
__author__ = 'BG'
import urllib2
import os
import re
class ZOLPIC:
def __init__(self):
if not os.path.exists('./PIC'):
os.mkdir(r'./PIC')
def getHtml(self,url):
try:
html = urllib2.urlopen(url)
html = html.read().decode('gbk').encode('utf-8')
return html
except:
return None
def startCrawler(self):
pic = [ "https://tgram.ru/stickers/dotastickers",
"https://tgram.ru/stickers/miawu",
"https://tgram.ru/stickers/YOTSUBA",
"https://tgram.ru/stickers/Gnu_Linux",
"https://tgram.ru/stickers/garfield",
"https://tgram.ru/stickers/punda",
"https://tgram.ru/stickers/MoviesNVR",
"https://tgram.ru/stickers/khafan2",
"https://tgram.ru/stickers/papcapic",
"https://tgram.ru/stickers/viber_Benny",
"https://tgram.ru/stickers/ZebraTelecom",
"https://tgram.ru/stickers/BeelineRacoon",
"https://tgram.ru/stickers/Tuzki_2",
"https://tgram.ru/stickers/SpongeBobStickers",
"https://tgram.ru/stickers/minion_rush",
"https://tgram.ru/stickers/nyapack",
"https://tgram.ru/stickers/viber_Kuma",
"https://tgram.ru/stickers/Tuziki",
"https://tgram.ru/stickers/pokelife",
"https://tgram.ru/stickers/CuttheRope",
"https://tgram.ru/stickers/FacebookLikes",
"https://tgram.ru/stickers/MemeStickers",
"https://tgram.ru/stickers/dotastickers"]
for p in pic:
cur_page = self.getHtml(p)
link_list = re.findall(r'<img class="img-responsive" src="(.*?)" alt=',cur_page)
file_path = r'./PIC/'+ p.split('/')[-1] + r'/'
if not os.path.exists(file_path):
print 'create folder %s' % file_path
os.mkdir(file_path)
for link in link_list:
file_name = file_path + link.split('/')[-1]
if not os.path.exists(file_name):
print 'download pic %s' % file_name
picsrc = urllib2.urlopen(link).read()
open( file_name,"wb").write(picsrc)
if __name__ == '__main__':
spider = ZOLPIC()
spider.startCrawler()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment