|
1 | 1 | #!/usr/bin/env python |
2 | 2 |
|
3 | | -## Instagram Post Image Downloader |
4 | | -## Install Python pip Modules |
5 | | - |
6 | | -# Python2 (pip) |
7 | | -## pip install wget |
8 | | -## pip install beautifulsoup4 |
9 | | -## pip install lxml |
| 3 | +## Install Python3 pip Modules |
10 | 4 |
|
11 | 5 | # Python3 (pip) |
12 | 6 | ## pip3 install wget |
13 | 7 | ## pip3 install beautifulsoup4 |
14 | 8 | ## pip3 install lxml |
15 | 9 |
|
| 10 | +from urllib.request import urlopen |
16 | 11 | from bs4 import BeautifulSoup |
17 | 12 | import wget |
18 | 13 |
|
19 | | -try: #python3 |
20 | | - from urllib.request import urlopen |
21 | | -except: #python2 |
22 | | - from urllib2 import urlopen |
23 | | - input = raw_input |
24 | | - |
25 | 14 | ## User input |
26 | | -url = input("\033[1;32mEnter a Instagram Post URL : \033[1;m") |
27 | | - |
28 | | -insta_post = urlopen(url) |
29 | | -bs = BeautifulSoup(insta_post , "lxml") |
30 | | - |
31 | | -## Find Insta Post Image URL |
32 | | -metatag = bs.find("meta", {"property": "og:image"}) |
| 15 | +URL = input("\033[1;32mEnter a Instagram Post URL : \033[1;m") |
33 | 16 |
|
34 | | -if metatag is not None: |
| 17 | +INSTA_POST = urlopen(URL) |
| 18 | +BS = BeautifulSoup(INSTA_POST, "lxml") |
35 | 19 |
|
36 | | - print (metatag["content"]) |
37 | | - print ("\n") |
| 20 | +## Find Insta Post Image |
| 21 | +METATAG = BS.find("meta", {"property": "og:image"}) |
38 | 22 |
|
39 | | - print ("Image Started Downloading.......") |
| 23 | +if METATAG is not None: |
40 | 24 |
|
41 | | - ## Download Image via Wget |
42 | | - filename = wget.download(metatag["content"]) |
43 | | - print ("\n") |
| 25 | + print(METATAG["content"]) |
| 26 | + print("Image Started Downloading.......") |
44 | 27 |
|
45 | | - print ("Done") |
46 | | - print ("\n") |
| 28 | + ## Download Image via Wget Method |
| 29 | + FILENAME = wget.download(METATAG["content"]) |
47 | 30 |
|
48 | 31 | else: |
49 | | - print ("Error") |
| 32 | + print("Error") |
0 commit comments