-
Notifications
You must be signed in to change notification settings - Fork 1
/
InstagramPost.py
91 lines (71 loc) · 2.32 KB
/
InstagramPost.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import os
import sys
import time
from selenium import webdriver
username = sys.argv[1]
password = sys.argv[2]
image = sys.argv[3]
description = sys.argv[4]
cwd = '/home/ubuntu/Desktop'
root_cwd = '/root/Desktop'
################################
# DOWNLOAD IMAGE
################################
if len(image) > 0:
os.system('wget -q "' + image + '" -O ' + cwd + '/pic.jpg')
################################
# FIREFOX
################################
user_agent = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16"
profile =webdriver.FirefoxProfile()
profile.set_preference("general.useragent.override", user_agent)
driver = webdriver.Firefox(profile,service_log_path=os.devnull)
driver.set_window_size(360,640)
driver.set_window_position(0,0)
################################
# LOGIN
################################
driver.get('https://www.instagram.com/accounts/login/?source=auth_switcher')
time.sleep(8)
field = driver.find_element_by_css_selector("input[type='text']")
field.send_keys(username)
field = driver.find_element_by_css_selector("input[type='password']")
field.send_keys(password)
time.sleep(2)
button=driver.find_elements_by_xpath("//*[contains(text(), 'Log In')]")
button[0].click()
time.sleep(10)
button=driver.find_elements_by_xpath("//*[contains(text(), 'Not Now')]")
if len(button) > 0:
button[0].click()
time.sleep(10)
button=driver.find_elements_by_xpath("//*[contains(text(), 'Cancel')]")
if len(button) > 0:
button[0].click()
################################
# SELECT IMAGE
################################
os.system('actiona -e ' + root_cwd + '/selectImage.ascr')
button=driver.find_elements_by_xpath("//*[contains(text(), 'Next')]")
button[0].click()
time.sleep(10)
################################
# ADD DESCRIPTION
################################
if len(description) > 0:
field = driver.find_elements_by_tag_name('textarea')[0]
field.click()
field.send_keys(description)
time.sleep(2)
################################
# POST!
################################
button=driver.find_elements_by_xpath("//*[contains(text(), 'Share')]")
button[1].click()
time.sleep(5)
################################
# SHUT IT DOWN
################################
# Remove all images
os.system('rm -f ' + cwd + '/*.jpg')
driver.quit()