-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.py
More file actions
55 lines (43 loc) · 1.96 KB
/
script.py
File metadata and controls
55 lines (43 loc) · 1.96 KB
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, time
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec
url = 'https://codeforces.com'
# Put your codeforces handle here
username = 'handle'
# Put your password here
password = 'password'
# Put the group ID here
# E.g: 'abc' in case of https://codeforces.com/group/abc
groupID = 'group_id'
URL = url + "/group/" + groupID + "/members"
r = requests.get(URL)
soup = BeautifulSoup(r.content, 'html5lib')
soup = soup.findAll('table')[1]
soup = soup.findAll('tr')
driver = webdriver.Firefox()
driver.get(url + "/enter")
element = WebDriverWait(driver, 10).until(ec.visibility_of_element_located((By.ID, "handleOrEmail")))
element.send_keys(username)
element = WebDriverWait(driver, 10).until(ec.visibility_of_element_located((By.ID, "password")))
element.send_keys(password)
element = WebDriverWait(driver, 10).until(ec.visibility_of_element_located((By.CSS_SELECTOR, ".submit")))
element.click()
element = WebDriverWait(driver, 10).until(ec.visibility_of_element_located((By.CSS_SELECTOR, ".header-bell__img")))
for i in range(1,len(soup)):
name = soup[i].findAll("a", {"class": "rated-user"})[0]
if name['href'].lower() == '/profile/' + username.lower():
continue
driver.get(url + name['href'])
element = WebDriverWait(driver, 10).until(ec.visibility_of_element_located((By.CSS_SELECTOR, ".friendStar")))
try:
element = driver.find_element_by_css_selector('.addFriend').click()
element = WebDriverWait(driver, 10).until(ec.visibility_of_element_located((By.CSS_SELECTOR, ".removeFriend")))
except:
continue
element = driver.find_element_by_css_selector('.lang-chooser > div:nth-child(2) > a:nth-child(2)').click()
element = WebDriverWait(driver, 6).until(ec.visibility_of_element_located((By.ID, "handleOrEmail")))
driver.quit()