diff --git a/tetras_extraction/macao_12/script/extract_page.py b/tetras_extraction/macao_12/script/extract_page.py index 6e1cb1f8dc3f255920791ffcefeb298dea565a79..e9b2691dd66c4bc14c2d26872dedd7a205501e0d 100644 --- a/tetras_extraction/macao_12/script/extract_page.py +++ b/tetras_extraction/macao_12/script/extract_page.py @@ -69,11 +69,10 @@ class Activity: for comment in self.comments_misc: graph.add((self.ref, NS["commentaireInfo"], Literal(comment.html))) - def parse_html(self, tree): + def parse_html(self, root: HtmlElement): """From a `lxml.html` parsing tree, extract all data relevant to this class. Subclasses may override this method to extract more specific data. """ - root = tree.getroot() # => Title self.title = root.xpath("/html/head/title")[0].text # => Comments @@ -126,17 +125,16 @@ class Activity: class Cours(Activity): - def parse_html(self, tree): - super().parse_html(tree) + def parse_html(self, root: HtmlElement): + super().parse_html(root) # => Description - cours = tree.getroot().get_element_by_id("STY_texteCours") + cours = root.get_element_by_id("STY_texteCours") self.description = to_html(cours).strip() class Exercice(Activity): - def parse_html(self, tree): - super().parse_html(tree) - root = tree.getroot() + def parse_html(self, root: HtmlElement): + super().parse_html(root) # => Description question = root.get_element_by_id("STY_question") self.description = to_html(question).strip() @@ -167,9 +165,8 @@ class ExerciceQC(Exercice): def get_name(self) -> str: return "ExerciceQC_QCM" if self.is_qcm else "ExerciceQC_QCU" - def parse_html(self, tree): - super().parse_html(tree) - root = tree.getroot() + def parse_html(self, root: HtmlElement): + super().parse_html(root) # Find question choices for choice in root.find_class("STY_reponseQC"): # Choices have an 'id' attribute in the form 'lienRepX' @@ -537,6 +534,6 @@ def parse_page(graph: Graph, filepath: str, id: str): activity.id = id # Parse the HTML portion - activity.parse_html(tree) + activity.parse_html(root) # Save everything to the graph activity.save(graph)