-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmajor_scrapper.py
36 lines (33 loc) · 1.21 KB
/
major_scrapper.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
import requests
from bs4 import BeautifulSoup
import sys
import collections
#major = "cse"
# TODO: return coreqs
def get_all_data(major):
url = "https://www.stonybrook.edu/sb/bulletin/current/courses/"+major+"/"
source_code = requests.get(url)
plain_text=source_code.text
soup = BeautifulSoup(plain_text, features="html.parser")
data = []
for link in soup.findAll('div',{'class' : 'course'}):
course_data = collections.defaultdict(str)
sbc = " "
title = link.find('h3').text
description = link.find('p').text
prerequisite = link.findAll('p')[1].text.replace('Prerequisite:', '')
if link.findAll('p')[2].text != "" or link.findAll('p')[2].text != "" or link.findAll('p')[2].text != " ":
sbc = link.findAll('p')[2].text
cred = link.findAll('p')[3].text
course_data["title"] = title
course_data["description"] = description
course_data["prereq"] = prerequisite
course_data["sbc"] = sbc
course_data["credits"] = cred
course_data["code"] = course_data["title"][4:7]
data.append(course_data)
return data
def get_course_data(course, code):
for item in get_all_data(course):
if item['code'] == code:
return item