-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.py
79 lines (63 loc) · 2.47 KB
/
main.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
import os
import time
from selenium import webdriver
from credentials import username, password, description_file
from selenium.webdriver.common import action_chains
# 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)
driver.set_window_size(360,640)
# CHROME/CHROMIUM
#from selenium.webdriver.chrome.options import Options
#mobile_emulation = {
# "deviceMetrics": { "width": 360, "height": 640, "pixelRatio": 3.0 },
# "userAgent": "Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19" }
#chrome_options = Options()
#chrome_options.add_experimental_option("mobileEmulation", mobile_emulation)
#driver = webdriver.Chrome(chrome_options = chrome_options)
url = 'https://www.instagram.com/accounts/login/?source=auth_switcher'
driver.get(url)
time.sleep(10)
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(5)
button=driver.find_elements_by_xpath("//*[contains(text(), 'Not Now')]")
if len(button) > 0:
button[0].click()
time.sleep(5)
button=driver.find_elements_by_xpath("//*[contains(text(), 'Cancel')]")
if len(button) > 0:
button[0].click()
time.sleep(2)
button = driver.find_elements_by_css_selector('[aria-label="New Post"]')
button[0].click()
os.system('autokey-run -s select_image')
time.sleep(10)
button=driver.find_elements_by_xpath("//*[contains(text(), 'Expand')]")
if len(button) > 0:
button[0].click()
time.sleep(20)
button=driver.find_elements_by_xpath("//*[contains(text(), 'Next')]")
button[0].click()
time.sleep(10)
field = driver.find_elements_by_tag_name('textarea')[0]
field.click()
with open(description_file, 'r') as file:
description = file.read()
field.send_keys(description)
time.sleep(15)
button = driver.find_elements_by_xpath("//*[contains(text(), 'Share')]")[1]
driver.execute_script("arguments[0].scrollIntoView();", button);
action = action_chains.ActionChains(driver)
action.move_to_element(button)
action.click()
action.perform()
time.sleep(15)
driver.quit()