<commit_before># Proof of Concept - Parse a Studentportal HTML file
# A: jhejdeurp
# TentaTimeProject
from lxml import html
import urllib


#This URL retrieves all course codes that contains a "D" and the list is sorted on Course codes
test_url = "https://www.student.chalmers.se/sp/examdates_list?flag=1;sortorder=C_CODE,CM_CODE,EX_DATE;search_course_code=dat050"

#Get the content
content = urllib.urlopen(test_url).read()
doc = html.fromstring(content)
doc.make_links_absolute(test_url)

content = doc.xpath('.//*[@id="contentpage"]//table[3]/tr[not(@class="tableHeader") and position()>1]')



print html.tostring(content[0])

<commit_msg>Using requests instead of urllib as it has improved speed and readability<commit_after># Proof of Concept - Parse a Studentportal HTML file
# A: jhejdeurp
# TentaTimeProject
from lxml import html
import requests


#This URL retrieves all course codes that contains a "D" and the list is sorted on Course codes
test_url = "https://www.student.chalmers.se/sp/examdates_list?flag=1;sortorder=C_CODE,CM_CODE,EX_DATE;search_course_code=dat050"

#Get the webpage
page = requests.get(test_url)
#Create a structured document
doc = html.fromstring(page.text)

#Get a list <td> elements for each exam
#The first row is removed as well as the tableheader
examdates_list = doc.xpath('.//*[@id="contentpage"]//table[3]/tr[not(@class="tableHeader") and position()>1]')


print html.tostring(examdates_list[0])


{'fraction_non_alphanumeric': 0.11388888888888889, 'fraction_numerical': 0.009722222222222222, 'mean_word_length': 6.029268292682927, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 6, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2122027', 'n_tokens_mistral': 494, 'n_tokens_neox': 478, 'n_words': 136}