<jupyter_start><jupyter_text>1. Obtain course titles<jupyter_code>course_blocks = page_soup.findAll("ul", {"class": "program-set"})
len(course_blocks)
course_blocks_eng = course_blocks[:-2]
len(course_blocks_eng)
#each container contains code, name, and desc for a course
containers = [container for course_block in course_blocks_eng for container in course_block.findAll("li", {"class": "program-course"})]
len(containers)
import re
course_titles = [re.split(" \([0-9]+ credit[s]*\)", container.a.text.strip())[0] for container in containers]
len(course_titles)
course_titles
course_titles = [title.replace("\r", "") for title in course_titles]
course_titles<jupyter_output><empty_output><jupyter_text>2. Obtain course codes and course names from course titles<jupyter_code>course_codes = [" ".join(title.split()[:2]) for title in course_titles]
course_codes
course_names = [" ".join(title.split()[2:]) for title in course_titles]
course_names<jupyter_output><empty_output><jupyter_text>3. Obtain course descriptions<jupyter_code>course_descs = [container.find("div", {"class": "content"}).p.text.strip() for container in containers]
len(course_descs)
course_descs<jupyter_output><empty_output><jupyter_text>4. Write to CSV<jupyter_code>import pandas as pd

df = pd.DataFrame({
    
    "Course Number": course_codes,
    "Course Name": course_names,
    "Course Description": course_descs    
    
})

df
df.to_csv('McGill_MechEng_Core_and_Electives_Courses.csv', index = False)<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup