-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub.py
71 lines (51 loc) · 2.09 KB
/
github.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
from userinfo import username, password
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
class Github:
def __init__(self, username, password):
self.browser = webdriver.Chrome()
self.username = username
self.password = password
self.followers = []
def signIn(self):
self.browser.get("https://github.com/login")
time.sleep(2)
self.browser.find_element(By.ID,"login_field").send_keys(self.username)
self.browser.find_element(By.ID, "password").send_keys(self.password)
time.sleep(1)
self.browser.find_element(By.NAME, "commit").click()
def loadFollowers(self):
items = self.browser.find_elements(By.CSS_SELECTOR, ".d-table.table-fixed")
for i in items:
self.followers.append(i.find_element(By.CSS_SELECTOR,".Link--secondary").text)
def getFollowers(self):
self.browser.get(f"https://github.com/{self.username}?tab=followers")
time.sleep(2)
pagination_container = self.browser.find_element(By.CLASS_NAME, "paginate-container")
links = pagination_container.find_elements(By.TAG_NAME, "a")
if pagination_container is not None:
if len(links) == 1:
if links[0].text == "Next":
links[0].click()
time.sleep(1)
self.loadFollowers()
elif len(links) == 0:
self.loadFollowers()
else:
for link in links:
if link.text == "Next":
link.click()
time.sleep(1)
self.loadFollowers()
else:
continue
else:
self.loadFollowers()
print(username, password)
github = Github(username, password)
github.signIn()
github.getFollowers()
print("followers: ", github.followers)
print("follower count: ", len(github.followers))
time.sleep(3)