-
Notifications
You must be signed in to change notification settings - Fork 1
/
first.py
69 lines (55 loc) · 2.62 KB
/
first.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
#imports
from selenium import webdriver
from selenium.webdriver.support import ui
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from random import randint
from time import sleep
import os
#the main function is called in instabot2 just after the bot is created
def main(driver,following):
#Function to follow 10 people the first time that the app is opened
#it will follow the 10 people that instagram reccomends
def follow_first():
for x in range (10):
sleep(1)
path="/html/body/div[1]/section/main/section/div/div/div/div/div/div["+str(x+1)+"]/div[3]/button"
driver.find_element_by_xpath(path).click()
#we append to the following list (list of the people that we are following)
#the people that we have just started following
name=driver.find_element_by_xpath("/html/body/div[1]/section/main/section/div/div/div/div/div/div["+str(x+1)+"]/div[2]/div[1]/div/span/a")
following.append(name.get_attribute("text"))
sleep(0.5)
sleep(5)
#we refresh the page
driver.refresh()
sleep(5)
#we call the function to add a profile image
photo()
#Function to add a profile image
def photo():
try:
#we click on the button to add a profile image
#and we execute the exe for window manipulation
#it will take as picture the one of the folder that has been created in pictures called instagram profile picture
driver.get("https://www.instagram.com/pepe97.gi/")
sleep(2)
driver.find_element_by_xpath("/html/body/div[1]/section/main/div/header/div/div/div/button").click()
#driver.find_element_by_xpath("/html/body/div[1]/section/main/section/div/div[2]/div[1]/div[2]/div/div/div/div/ul/li[5]/div/div/div/div/button").click()
sleep(3)
os.system('"C:\\Users\lmoli\Desktop\SAMUEL\TERCERO\PROGRAMACIÓN\INSTAGRAM\\Profile.exe"')
sleep(7)
#finally, we refresh and quit the broser
driver.refresh()
sleep(5)
except:
print("error")
pass
#we call the follow_first function
follow_first()
driver.quit()
sleep(4)