-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraw_winner.py
55 lines (43 loc) · 1.55 KB
/
draw_winner.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
import requests
from bs4 import BeautifulSoup
import random
username = "cdxiaodong"
page = 1
followers = []
while True:
followers_url = f"https://github.com/{username}?page={page}&tab=followers"
print(f"Fetching page {page} from {followers_url}")
response = requests.get(followers_url)
if response.status_code == 200:
soup = BeautifulSoup(response.text, 'html.parser')
current_followers = soup.find_all('span', class_='Link--secondary')
if not current_followers:
print(f"No more followers found on page {page}")
break
followers.extend([follower.text.strip() for follower in current_followers])
print(f"Found {len(current_followers)} followers on page {page}")
next_page_link = soup.find('a', {'class': 'next_page'})
if not next_page_link:
print("No next page link found")
break
page += 1
else:
print(f"Failed to retrieve followers. Status code: {response.status_code}")
break
print("All followers:")
for follower in followers:
print(follower)
target_name = "AnneLau"
filtered_followers = []
for follower in followers:
if follower == target_name:
break
filtered_followers.append(follower)
print(f"\nFiltered followers before '{target_name}':")
for follower in filtered_followers:
print(follower)
if filtered_followers:
winner = random.choice(filtered_followers)
print(f"\nThe winner is: {winner}")
else:
print("\nNo followers found before the target name.")