-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstabot.py
More file actions
119 lines (101 loc) · 3.99 KB
/
instabot.py
File metadata and controls
119 lines (101 loc) · 3.99 KB
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
# -*- coding: utf-8 -*-
__author__ = 'vlad'
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import random
import time
import re
def instaBot (gLogin, gPassword, gTags, gLimit):
limit = gLimit
smt = 10
max = 3
templikes = 0
def wait():
driver.implicitly_wait(smt)
driver = webdriver.Firefox()
# логинимся на инстаком
driver.get('https://instagram.com/accounts/login/')
wait()
# ввод логина
login = driver.find_element_by_id('lfFieldInputUsername')
login.send_keys(gLogin)
# ввод пароля
password = driver.find_element_by_id('lfFieldInputPassword')
password.send_keys(gPassword)
# сабмит
button = driver.find_element_by_class_name('-cx-PRIVATE-LoginForm__loginButton')
button.click()
wait()
tags = re.findall(r'[#]\w+', gTags)
print(tags)
for tag in tags:
# поиск по хештегам
find = driver.find_element_by_class_name('-cx-PRIVATE-SearchBox__input')
find.send_keys(tag)
wait()
# переход по хештегу
human = driver.find_element_by_class_name('-cx-PRIVATE-Search__resultLink')
human.click()
wait()
# открытие фоточки
link = driver.find_elements_by_class_name('-cx-PRIVATE-PostsGrid__item')
link[0].click()
wait()
i=0
while i<(random.randint(5,15)):
# открытие страницы человека
person = driver.find_element_by_class_name('-cx-PRIVATE-Post__ownerUserLink')
person.click()
wait()
time.sleep(5)
# определение количества лайков которые будут поставлены человеку
personPhotoLink = driver.find_elements_by_class_name('-cx-PRIVATE-Photo__root')
maxLikes = random.randint(3,len(personPhotoLink))
it = 0
while (it < maxLikes):
personPhotoLink[it].click()
# ищем кнопку Лайк, отсеевая фото которые уже лайкнули
try:
if templikes < limit:
like = driver.find_element_by_link_text('Like')
like.click()
except:
pass
else:
templikes +=1
# добавляем хештеги
try:
h1 = driver.find_element_by_class_name('-cx-PRIVATE-PostInfo__comment').text
hashTags = re.findall(r'[#]\w+', h1)
k=0
if (max > len(hashTags)):
max = len(hashTags)
while (k<max):
if ((hashTags[k] not in tags)):
tags.append(hashTags[k])
k += 1
except:
pass
driver.back()
it +=1
i += 1
driver.back()
driver.back()
time.sleep(3)
link = driver.find_elements_by_class_name('-cx-PRIVATE-PostsGrid__item')
link[i].click()
driver.get('https://instagram.com/')
time.sleep(random.randint(60,6000))
"""#link = driver.
link = driver.find_element_by_class_name('-cx-PRIVATE-PostsGrid__item')
link.click()
like = driver.find_element_by_class_name('-cx-PRIVATE-PostInfo__likeButton')
like.click()
closeButton = driver.find_element_by_class_name('-cx-PRIVATE-Modal__closeButton')
closeButton.click()
""""""human = driver.find_element_by_class_name('-cx-PRIVATE-ProfilePage__header')
human1 = driver.find_element_by_class_name('-cx-PRIVATE-ProfilePage__authorInfo')
human2 = driver.find_element_by_class_name('-cx-PRIVATE-ProfilePage__usernameAndFollow')
span = driver.find_element_by_tag_name('span')
submit = driver.find_element_by_tag_name('button')"""
#submit.click()"""