-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
45 lines (41 loc) · 1.89 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
from selenium import webdriver
from time import sleep
import personal
class InstaBot:
def __init__(self, username, pw):
self.driver = webdriver.Chrome()
self.username = username
self.driver.get("https://instagram.com")
sleep(2)
self.driver.find_element_by_xpath('/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div[1]/button').click()
sleep(2)
self.driver.find_element_by_xpath("/html/body/div[1]/div[3]/div[1]/div/div/div[2]/div[1]/form/div/div[1]/input").send_keys(username)
self.driver.find_element_by_xpath("/html/body/div[1]/div[3]/div[1]/div/div/div[2]/div[1]/form/div/div[2]/input").send_keys(pw)
self.driver.find_element_by_xpath("/html/body/div[1]/div[3]/div[1]/div/div/div[2]/div[1]/form/div/div[3]/button").click()
sleep(2)
self.driver.find_element_by_xpath("//*[text()='Not Now']").click()
sleep(1)
def _go_to_profile(self):
sleep(2)
self.driver.find_element_by_xpath("/html/body/div[1]/section/nav/div[2]/div/div/div[3]/div/div[3]/a").click()
sleep(2)
def get_names(self):
self._go_to_profile()
self.driver.find_element_by_xpath("//a[contains(@href,'/following')]")\
.click()
sleep(2)
print("dsfdssdf")
scroll_box = self.driver.find_element_by_xpath("/html/body/div[4]/div/div[2]")
last_ht, ht = 0, 1
while last_ht != ht:
last_ht = ht
sleep(1)
ht = self.driver.execute_script("""
arguments[0].scrollTo(0, arguments[0].scrollHeight);
return arguments[0].scrollHeight;
""", scroll_box)
links = scroll_box.find_elements_by_class_name('d7ByH')
names = [name.text for name in links if name.text != '']
return names
my_bot = InstaBot(personal.username, personal.password)
print(my_bot.get_names())