-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRobat.py
182 lines (162 loc) · 8.47 KB
/
Robat.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import re
import time
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
class Robo:
counter = 1
speed = 0
def __init__(self):
a = input('Enter the speed limit :')
while True:
try:
a = int(a)
except:
pass
if type(a) == int and a >= 0:
self.speed = a
break
a = input('Enter the speed limit :')
self.driver = webdriver.Firefox()
# login insta
self.driver.get('https://www.instagram.com/accounts/login/')
sleep(2)
# self.driver.find_element_by_xpath('//*[@id="loginForm"]/div/div[1]/div/label/input').send_keys(
# 'navaiiymohaahmd38')
# self.driver.find_element_by_xpath('//*[@id="loginForm"]/div/div[2]/div/label/input').send_keys(
# 'gV33vmaAcxCyacr')
sdf = input('Enter to login to Instagram :')
self.driver.find_element_by_xpath('//*[@id="loginForm"]/div[1]/div[3]/button/div').click() # submit
sleep(5)
self.driver.get('https://getlike.io/login/')
sleep(2)
# login
sdf = input('Enter to login to Getlike :')
sleep(2)
self.driver.find_element_by_xpath('//*[@id="formLogin"]/input').click() # btn_login
print("login")
sleep(5)
self.driver.find_element_by_xpath('/html/body/div[6]/nav/div/div[2]/ul[1]/li[2]/a').click() # Quest Exchange
sleep(1)
def follow(self):
self.driver.find_element_by_xpath('//*[@id="list-3-3"]/span[2]').click() # part flower
sleep(2)
id_text = self.driver.find_element_by_xpath('//*[@id="task_list"]/div/div[2]').get_attribute('innerHTML')
ids = list()
for sublist in [c[14:] for c in re.findall(r'data-task-id="[\d]+', id_text)]:
if sublist not in ids:
ids.append(sublist)
for i, id in enumerate(ids):
t = time.time()
try:
print('========================================================')
print(self.counter, end=' > ')
self.counter += 1
# WebDriverWait(self.driver, 5).until(EC.presence_of_element_located((By.XPATH,
# f'/html/body/div[6]/div[1]/div/div[2]/div/div[2]/article[{i + 1}]/div/div/div/div[4]/a')))
sleep(3)
self.driver.find_element_by_xpath(
f'/html/body/div[6]/div[1]/div/div[2]/div/div[2]/article[{i + 1}]/div/div/div/div[4]/a').click()
sleep(1)
try:
self.driver.find_element_by_xpath(
f"/html/body/div[6]/div[1]/div/div[2]/div/div[2]/article[{i + 1}]/div/div/div/div[4]/span/i").get_attribute(
'class')
except:
sleep(10 + self.speed)
self.driver.switch_to.window(self.driver.window_handles[1])
self.driver.find_element_by_xpath('/html/body/div[1]/section/main/div/header/section/div[1]/div[1]/div/div/div/span/span[1]').click()
print(self.driver.title.split('•')[0], end=' > ')
#
# self.driver.find_element_by_css_selector(
# '#react-root > section > main > div > header > section > div.nZSzR > div.Igw0E.IwRSH.eGOV_.ybXk5._4EzTm.bPdm3 > div > div > div > span > span.vBF20._1OSdk > button').click()
sleep(1)
print('flow', end=' > ')
self.driver.close()
sleep(1)
self.driver.switch_to.window(self.driver.window_handles[0])
# WebDriverWait(self.driver, 5).until(EC.presence_of_element_located((By.XPATH,
# f'/html/body/div[6]/div[1]/div/div[2]/div/div[2]/article[{i + 1}]/div/div/div/div[4]/a')))
sleep(2)
self.driver.find_element_by_xpath(
f'/html/body/div[6]/div[1]/div/div[2]/div/div[2]/article[{i + 1}]/div/div/div/div[4]/a').click()
print('ok', end=' ')
except Exception as e:
print('error', end=' ')
try:
self.driver.switch_to.window(self.driver.window_handles[1])
self.driver.close()
self.driver.switch_to.window(self.driver.window_handles[0])
self.driver.find_element_by_css_selector(
f'#task-item-{id} > div > div > div > div.media-right.media-middle.task-btn > a').click() # Quest Exchange
except:
pass
print(f'time = {int(time.time() - t)}')
def like(self):
self.driver.find_element_by_xpath('//*[@id="list-3-1"]').click() # part flower
sleep(2)
id_text = self.driver.find_element_by_xpath('//*[@id="task_list"]/div/div[2]').get_attribute('innerHTML')
ids = list()
for sublist in [c[14:] for c in re.findall(r'data-task-id="[\d]+', id_text)]:
if sublist not in ids:
ids.append(sublist)
for i, id in enumerate(ids):
t = time.time()
try:
print('========================================================')
print(self.counter, end=' > ')
self.counter += 1
# WebDriverWait(self.driver, 5).until(EC.presence_of_element_located((By.XPATH, f'/html/body/div[6]/div[1]/div/div[2]/div/div[2]/article[{i+1}]/div/div/div/div[4]/a')))
sleep(3)
self.driver.find_element_by_xpath(
f'/html/body/div[6]/div[1]/div/div[2]/div/div[2]/article[{i + 1}]/div/div/div/div[4]/a').click()
sleep(1)
try:
self.driver.find_element_by_xpath(
f"/html/body/div[6]/div[1]/div/div[2]/div/div[2]/article[{i + 1}]/div/div/div/div[4]/span/i").get_attribute(
'class')
except:
sleep(10 + self.speed)
self.driver.switch_to.window(self.driver.window_handles[1])
# WebDriverWait(self.driver, 10).until(EC.presence_of_element_located(
# (By.XPATH, '//*[@id="react-root"]/section/main/div/div[1]/article/div[3]/section[1]/span[1]')))
self.driver.find_element_by_xpath('/html/body/div[1]/section/main/div/div[1]/article/div[3]/section[1]/span[1]/button').click()
print(self.driver.title.split('on')[0], end=' > ')
# self.driver.find_element_by_xpath(
# '//*[@id="react-root"]/section/main/div/div[1]/article/div[3]/section[1]/span[1]').click()
sleep(1)
print('like', end=' > ')
self.driver.close()
sleep(1)
self.driver.switch_to.window(self.driver.window_handles[0])
# WebDriverWait(self.driver, 5).until(EC.presence_of_element_located((By.XPATH,
# f'/html/body/div[6]/div[1]/div/div[2]/div/div[2]/article[{i + 1}]/div/div/div/div[4]/a')))
sleep(2)
self.driver.find_element_by_xpath(
f'/html/body/div[6]/div[1]/div/div[2]/div/div[2]/article[{i + 1}]/div/div/div/div[4]/a').click()
print('ok', end=' ')
except Exception as e:
print('error', end=' ')
try:
self.driver.switch_to.window(self.driver.window_handles[1])
self.driver.close()
self.driver.switch_to.window(self.driver.window_handles[0])
self.driver.find_element_by_css_selector(
f'#task-item-{id} > div > div > div > div.media-right.media-middle.task-btn > a').click() # Quest Exchange
except:
pass
print(f'time = {int(time.time() - t)}')
now = time.localtime() # زمان فعلی سیستم
sec = time.mktime(now)
try:
if sec < 7624304618+172800:
robo = Robo()
while sec < 7624304618+172800:
robo.follow()
robo.follow()
robo.like()
except Exception as e:
print("Please run the program again\n")
print(f'error =>{e}')