-
Notifications
You must be signed in to change notification settings - Fork 0
/
insta.py
47 lines (38 loc) · 1.03 KB
/
insta.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
import os
import urllib
username = raw_input("Enter username: ")
chromedriver = "/home/vicodin/chromedriver"
os.environ["webdriver.chrome.driver"] = chromedriver
browser = webdriver.Chrome(chromedriver)
browser.set_window_size(1120, 550)
url = 'https://instagram.com/'+ username
browser.get(url)
time.sleep(3)
body = browser.find_element_by_tag_name("body")
while True:
body.send_keys(Keys.END)
time.sleep(3)
more = body.find_element_by_tag_name('button')
disabled_btn = more.get_attribute('class')
if disabled_btn == 'PhotoGridMoreButton pgmbDisabled':
print "disabled button found"
break
else:
more.click()
print "all photos loaded"
count = 0
photos = body.find_elements_by_class_name('pgmiThumb')
for link in photos:
photo_src = link.get_attribute('src')
if photo_src != None:
photo_name = str(count)+".jpg"
urllib.urlretrieve(photo_src, photo_name)
else:
pass
count += 1
print count
html_source = browser.page_source
browser.quit()