-
Notifications
You must be signed in to change notification settings - Fork 0
/
liker.py
115 lines (98 loc) · 3.74 KB
/
liker.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
import selenium.common.exceptions
driver = webdriver.Chrome("./chromedriver")
number = 4
username = "username"
password = "password"
def like_pic():
time.sleep(2)
like = driver.find_element_by_class_name('fr66n')
like.find_element_by_tag_name('button').click()
# soup = bs(like.get_attribute('innerHTML'),'html.parser')
# if(soup.find('svg')['aria-label'] == 'Like'):
# like.click()
# time.sleep(2)
def next_picture():
time.sleep(2)
try:
nex = driver.find_element_by_class_name("coreSpriteRightPaginationArrow")
time.sleep(1)
return nex
except selenium.common.exceptions.NoSuchElementException:
return 0
def continue_liking():
count = 0
while(True):
next_el = next_picture()
# if next button is there then
if next_el != False and count <= 23:
# click the next button
next_el.click()
time.sleep(2)
# like the picture
like_pic()
time.sleep(2)
count+=1
else :
print("not found")
break
def goBack():
time.sleep(2)
cross = driver.find_element_by_xpath('/html/body/div[5]/div[3]')
cross.find_element_by_class_name('wpO6b').click()
# driver.find_element_by_xpath('/html/body/div[5]/button').click()
driver.find_element_by_xpath('//*[@id="react-root"]/section/nav/div[2]/div/div/div[3]/div/div[5]/span/img').click()
time.sleep(4)
driver.find_element_by_xpath('//*[@id="react-root"]/section/nav/div[2]/div/div/div[3]/div/div[5]/div[2]/div[2]/div[2]/a[1]/div').click()
time.sleep(4)
driver.find_element_by_xpath('//*[@id="react-root"]/section/main/div/div[2]/article/div/div/div[1]/div[1]/a/div/div[2]').click()
global number
number+=1
print(number)
if(number == 22):
return
time.sleep(3)
newTag(number)
def tagsLike(e):
e.click()
time.sleep(5)
driver.find_element_by_xpath('//*[@id="react-root"]/section/main/article/div[2]/div/div[1]/div[1]/a/div/div[2]').click()
time.sleep(5)
like_pic()
continue_liking()
time.sleep(3)
goBack()
def newTag(num):
contet = driver.find_element_by_xpath('/html/body/div[5]/div[2]/div/article/div[3]/div[1]/ul/div/li/div/div/div[2]')
tags = contet.find_elements_by_tag_name('a')
count = 0
tagsLike(tags[num])
# for e in tags:
# count+=1
# if(count>num):
# tagsLike(e)
# break
driver.get("https://www.instagram.com/")
time.sleep(3)
driver.maximize_window()
# find username/email field and send the username itself to the input field
# driver.find_element_by_name("login").send_keys("hello")
# find password input field and insert password as well
driver.find_element_by_xpath('//*[@id="loginForm"]/div/div[1]/div/label/input').send_keys(username)
driver.find_element_by_xpath('//*[@id="loginForm"]/div/div[2]/div/label/input').send_keys(password)
# click login button
time.sleep(2)
driver.find_element_by_xpath('//*[@id="loginForm"]/div/div[3]/button').click()
time.sleep(6)
driver.find_element_by_xpath('//*[@id="react-root"]/section/main/div/div/div/div/button').click()
time.sleep(4)
driver.find_element_by_xpath('/html/body/div[4]/div/div/div/div[3]/button[2]').click()
driver.find_element_by_xpath('//*[@id="react-root"]/section/nav/div[2]/div/div/div[3]/div/div[5]/span/img').click()
time.sleep(4)
driver.find_element_by_xpath('//*[@id="react-root"]/section/nav/div[2]/div/div/div[3]/div/div[5]/div[2]/div[2]/div[2]/a[1]/div').click()
time.sleep(4)
driver.find_element_by_xpath('//*[@id="react-root"]/section/main/div/div[2]/article/div/div/div[1]/div[1]/a/div/div[2]').click()
time.sleep(3)
newTag(number)