-
Notifications
You must be signed in to change notification settings - Fork 1
/
unfollower.py
146 lines (123 loc) · 4.15 KB
/
unfollower.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
import selenium
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from time import sleep
import csv
from selenium.common.exceptions import NoSuchElementException
cred = open('info.txt','rt')
context = cred.read()
context = context.split('\n')
user_name = context[0]
user_pass = context[1]
def extract_digit(digit):
y = ''
for i in digit:
if i.isdigit():
y += i
return int(y)
PATH = "chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get("https://github.com/login")
sleep(3)
username = driver.find_element(By.XPATH,'//input[@name="login"]')
username.send_keys(user_name)
sleep(3)
password = driver.find_element(By.XPATH,'//input[@name="password"]')
password.send_keys(user_pass)
sleep(3)
submit = driver.find_element(By.XPATH,'//input[@type="submit"]')
submit.click()
sleep(3)
try:
drop = driver.find_element(By.XPATH,'/html/body/div[1]/header/div[7]/details/summary')
drop.click()
sleep(3)
pth = f'//details-menu//a[@href="/{user_name}"][@role="menuitem"][@class="dropdown-item"]'
profile = driver.find_element(By.XPATH,pth)
profile.click()
sleep(3)
except NoSuchElementException:
nav = driver.find_element(By.XPATH,'//button[@aria-label="Toggle navigation"]')
nav.click()
pth = f'//nav//a[@href="/{user_name}"]'
profile = driver.find_element(By.XPATH,pth)
profile.click()
sleep(10)
pth = f'//a[@href="https://github.com/{user_name}?tab=followers"]'
follower = driver.find_element(By.XPATH,pth)
follower.click()
followers_lst=[]
followers = extract_digit(follower.text)
follower_count = 0
while True:
if followers > 48:
sleep(2)
user_followers = driver.find_elements(By.XPATH,'//span[@class ="Link--secondary pl-1"]')
for i in user_followers:
followers_lst.append(i.text)
# follower_count += len(user_followers)
follower_count += 48
if follower_count >= followers:
break
else:
try:
sleep(2)
Next = driver.find_element(By.XPATH,'//a[contains(text(),"Next")]')
Next.click()
sleep(1)
except NoSuchElementException:
pass
else:
break
else:
sleep(2)
user_followers = driver.find_elements(By.XPATH,'//span[@class ="Link--secondary pl-1"]')
for i in user_followers:
followers_lst.append(i.text)
break
sleep(3)
lst = [[i] for i in followers_lst]
filename = csv.writer(open("myfollowers.csv","w",newline=''),delimiter=',')
filename.writerows(lst)
sleep(1)
pth = f'//a[@href="https://github.com/{user_name}?tab=following"]'
following = driver.find_element(By.XPATH,pth)
following.click()
followings = extract_digit(following.text)
followings_count = 0
sleep(4)
while True:
if followings > 48:
sleep(2)
user_followings = driver.find_elements(By.XPATH,'//span[@class ="Link--secondary pl-1"]')
for i in user_followings:
if i.text not in followers_lst:
pth = f'//input[@title="Unfollow {i.text}"]'
user = driver.find_element(By.XPATH,pth)
user.click()
followings_count += len(user_followings)
if followings_count >= followings:
break
else:
try:
sleep(2)
Next = driver.find_element(By.XPATH,'//a[contains(text(),"Next")]')
Next.click()
sleep(1)
except NoSuchElementException:
sleep(1)
pth = f'//a[@href="https://github.com/{user_name}?tab=following"]'
following = driver.find_element(By.XPATH,pth)
following.click()
pass
else:
sleep(3)
user_followings = driver.find_elements(By.XPATH,'//span[@class ="Link--secondary pl-1"]')
for i in user_followings:
if i.text not in followers_lst:
pth = f'//input[@title="Unfollow {i.text}"]'
user = driver.find_element(By.XPATH,pth)
user.click()
break
driver.close()