-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrnBot.py
More file actions
53 lines (41 loc) · 1.61 KB
/
crnBot.py
File metadata and controls
53 lines (41 loc) · 1.61 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
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
import pandas as pd
URL_FIRST = "https://central.carleton.ca/prod/bwysched.p_display_course?wsea_code=EXT&term_code="
URL_SECOND = "&disp=18292988&crn="
CRN_CSV_PATH = 'crns.csv'
class CrnBot:
def __init__(self):
self.df = pd.DataFrame(columns=['termCode', 'crns',])
self.terms = [
{
"name": "W2023",
"urlValue": "202310",
"validCRNs": [],
"startCRN": 10000,
"endCRN" : 10009,
},
{
"name": "S2023",
"urlValue": "202320",
"validCRNs": [],
"startCRN": 20000,
"endCRN" : 20009,
},
]
options = Options()
options.add_experimental_option("detach", True)
self.driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()),options = options)
def scrape(self):
for term in self.terms:
url = URL_FIRST + (term["urlValue"]) + URL_SECOND
for j in range(term["startCRN"], term["endCRN"]):
self.driver.get(url + str(j))
if not self.driver.find_elements(By.CLASS_NAME, 'warningtext'):
term["validCRNs"].append(j)
self.df.loc[len(self.df)] = [term["urlValue"], term["validCRNs"]]
self.driver.close()
self.df.to_csv(CRN_CSV_PATH, index=False)