Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- #Usage: Scroll down to the bottom of a instagram page, copy the LIVE HTML source and save it as a file.
- #Usage: Then start the script with "source.html" "/home/me/downloads"
- import sys
- import urllib2
- import re
- import os
- from os.path import basename
- x=0
- infomsg=('\033[92m<INFO>\033[0m')
- completemsg=('\033[94m<COMPLETE>\033[0m')
- container=[]
- sorted_container=[]
- rpath=str(sys.argv[1])
- dpath=str(sys.argv[2])
- with open(rpath, 'r') as ss:
- data=ss.read().replace('\n', '')
- print('%s Input file is \033[94m%s\033[0m containing %s characters' % (infomsg,basename(rpath),len(data)))
- parts=data.split('instagram.com/')
- for i in parts:
- if i.startswith('p/'):
- container.append((i.split('/')[1]))
- [sorted_container.append(item) for item in container if item not in sorted_container]
- print('%s Analyzed code and found %s items out of %s potention items' % (infomsg,len(sorted_container),len(container)))
- print('%s Initiating download' % infomsg)
- for p in sorted_container:
- url=('http://instagram.com/p/%s/' % p)
- req=urllib2.Request(url,headers={'User-Agent' : 'Mozilla Firefox'})
- u=urllib2.urlopen(req)
- iurl=(str(u.read().split('<meta property="og:image" content="')[1]).split('"')[0])
- req=urllib2.Request(iurl,headers={'User-Agent' : 'Mozilla Firefox'})
- i=urllib2.urlopen(req)
- sFile=open(('%s/%s' % (dpath,p)),'w')
- sFile.write(i.read())
- sFile.close()
- if os.path.isfile(('%s/%s' % (dpath,p))):
- x+=1
- print('%s %s %s/%s' % (completemsg,p,x,len(sorted_container)))
- print('%s %s/%s images downloaded!' % (completemsg,x,len(sorted_container)))
Advertisement
Add Comment
Please, Sign In to add comment