-
Notifications
You must be signed in to change notification settings - Fork 5
/
follow_bot.py
54 lines (43 loc) · 1.6 KB
/
follow_bot.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
import time
import sys
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# Initializing the headless chrome
driver = webdriver.Chrome()
driver.get("https://github.com/login")
wait = WebDriverWait(driver, 10)
# Locating username and password field
username = wait.until(EC.presence_of_element_located((By.ID, "login_field")))
password = wait.until(EC.presence_of_element_located((By.ID, "password")))
# password and username need to go into these values
username.send_keys("username")
password.send_keys("password")
# Clicking the sign in button
login_form = wait.until(EC.presence_of_element_located((By.XPATH, "//input[@value='Sign in']")))
login_form.click()
# Go to the followers tab
nameOfUser = "" # Input github username here
driver.get("https://github.com/{}?tab=followers".format(nameOfUser))
time.sleep(3)
# Find the followers
users = driver.find_elements_by_xpath("//a[@data-hovercard-type='user']")
temp = []
for follower in users:
temp.append(follower.get_attribute("href"))
list_set = set(temp)
followers = (list(list_set))
# Follow everyone who is following 'nameOfUser'
for user in followers:
for page in range(1, 5):
string = "{}?page={}&tab=following".format(user, page)
driver.get(string)
time.sleep(3)
follow_button = driver.find_elements_by_xpath("//input[@aria-label='Follow this person']")
try:
for i in follow_button:
i.submit()
except:
pass
driver.close()