Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Macao Legacy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MACAO
Macao Legacy
Commits
56ae8f77
Commit
56ae8f77
authored
1 year ago
by
Eliott Sammier
Browse files
Options
Downloads
Patches
Plain Diff
Minor signature change for parse_html()
parent
45c689ab
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
tetras_extraction/macao_12/script/extract_page.py
+9
-12
9 additions, 12 deletions
tetras_extraction/macao_12/script/extract_page.py
with
9 additions
and
12 deletions
tetras_extraction/macao_12/script/extract_page.py
+
9
−
12
View file @
56ae8f77
...
@@ -69,11 +69,10 @@ class Activity:
...
@@ -69,11 +69,10 @@ class Activity:
for
comment
in
self
.
comments_misc
:
for
comment
in
self
.
comments_misc
:
graph
.
add
((
self
.
ref
,
NS
[
"
commentaireInfo
"
],
Literal
(
comment
.
html
)))
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.
"""
From a `lxml.html` parsing tree, extract all data relevant to this class.
Subclasses may override this method to extract more specific data.
Subclasses may override this method to extract more specific data.
"""
"""
root
=
tree
.
getroot
()
# => Title
# => Title
self
.
title
=
root
.
xpath
(
"
/html/head/title
"
)[
0
].
text
self
.
title
=
root
.
xpath
(
"
/html/head/title
"
)[
0
].
text
# => Comments
# => Comments
...
@@ -126,17 +125,16 @@ class Activity:
...
@@ -126,17 +125,16 @@ class Activity:
class
Cours
(
Activity
):
class
Cours
(
Activity
):
def
parse_html
(
self
,
tree
):
def
parse_html
(
self
,
root
:
HtmlElement
):
super
().
parse_html
(
tree
)
super
().
parse_html
(
root
)
# => Description
# => Description
cours
=
tree
.
get
root
()
.
get_element_by_id
(
"
STY_texteCours
"
)
cours
=
root
.
get_element_by_id
(
"
STY_texteCours
"
)
self
.
description
=
to_html
(
cours
).
strip
()
self
.
description
=
to_html
(
cours
).
strip
()
class
Exercice
(
Activity
):
class
Exercice
(
Activity
):
def
parse_html
(
self
,
tree
):
def
parse_html
(
self
,
root
:
HtmlElement
):
super
().
parse_html
(
tree
)
super
().
parse_html
(
root
)
root
=
tree
.
getroot
()
# => Description
# => Description
question
=
root
.
get_element_by_id
(
"
STY_question
"
)
question
=
root
.
get_element_by_id
(
"
STY_question
"
)
self
.
description
=
to_html
(
question
).
strip
()
self
.
description
=
to_html
(
question
).
strip
()
...
@@ -167,9 +165,8 @@ class ExerciceQC(Exercice):
...
@@ -167,9 +165,8 @@ class ExerciceQC(Exercice):
def
get_name
(
self
)
->
str
:
def
get_name
(
self
)
->
str
:
return
"
ExerciceQC_QCM
"
if
self
.
is_qcm
else
"
ExerciceQC_QCU
"
return
"
ExerciceQC_QCM
"
if
self
.
is_qcm
else
"
ExerciceQC_QCU
"
def
parse_html
(
self
,
tree
):
def
parse_html
(
self
,
root
:
HtmlElement
):
super
().
parse_html
(
tree
)
super
().
parse_html
(
root
)
root
=
tree
.
getroot
()
# Find question choices
# Find question choices
for
choice
in
root
.
find_class
(
"
STY_reponseQC
"
):
for
choice
in
root
.
find_class
(
"
STY_reponseQC
"
):
# Choices have an 'id' attribute in the form 'lienRepX'
# Choices have an 'id' attribute in the form 'lienRepX'
...
@@ -537,6 +534,6 @@ def parse_page(graph: Graph, filepath: str, id: str):
...
@@ -537,6 +534,6 @@ def parse_page(graph: Graph, filepath: str, id: str):
activity
.
id
=
id
activity
.
id
=
id
# Parse the HTML portion
# Parse the HTML portion
activity
.
parse_html
(
tree
)
activity
.
parse_html
(
root
)
# Save everything to the graph
# Save everything to the graph
activity
.
save
(
graph
)
activity
.
save
(
graph
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment