Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CTF Search
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
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CTF Search Team
CTF Search
Commits
628858e6
Commit
628858e6
authored
5 years ago
by
Timmy Chan
Browse files
Options
Downloads
Patches
Plain Diff
Add html table parser
parent
e666f238
No related branches found
No related tags found
1 merge request
!5
Feat/cve linux kernel
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
exploitdb/ctfsetup/qemu/.gitignore
+1
-2
1 addition, 2 deletions
exploitdb/ctfsetup/qemu/.gitignore
exploitdb/ctfsetup/qemu/lib/html_table_parser.py
+90
-0
90 additions, 0 deletions
exploitdb/ctfsetup/qemu/lib/html_table_parser.py
with
91 additions
and
2 deletions
exploitdb/ctfsetup/qemu/.gitignore
+
1
−
2
View file @
628858e6
.vscode
.vscode
/.vs/
/.vs/
vms/*
vms/*
lib/
*
lib/
buildroot/
.idea/*
.idea/*
!lib/kconfiglib.py
!vms/.keep
!vms/.keep
buildroot_setup_config.txt*
buildroot_setup_config.txt*
\ No newline at end of file
This diff is collapsed.
Click to expand it.
exploitdb/ctfsetup/qemu/lib/html_table_parser.py
0 → 100644
+
90
−
0
View file @
628858e6
import
re
from
abc
import
ABC
from
html.parser
import
HTMLParser
from
datetime
import
datetime
class
TableHTMLParser
(
HTMLParser
,
ABC
):
"""
Parse all table data of a HTML document string
"""
def
__init__
(
self
):
super
().
__init__
()
self
.
tables
=
[]
self
.
_current_table
=
[]
self
.
_current_row
=
[]
self
.
_current_cell
=
[]
self
.
_hierarchy
=
[]
def
handle_starttag
(
self
,
tag
,
attrs
):
self
.
handle_starttag_sub
(
tag
,
attrs
)
if
tag
in
[
'
th
'
,
'
td
'
]:
self
.
_hierarchy
.
append
(
tag
)
def
handle_data
(
self
,
data
):
if
any
(
x
in
self
.
_hierarchy
for
x
in
[
'
th
'
,
'
td
'
]):
self
.
_current_cell
.
append
(
data
.
strip
())
def
handle_endtag
(
self
,
tag
):
if
tag
in
[
'
td
'
,
'
th
'
]:
self
.
_hierarchy
.
pop
()
merged_cell
=
'
'
.
join
(
self
.
_current_cell
).
strip
()
self
.
_current_row
.
append
(
merged_cell
)
self
.
_current_cell
=
[]
elif
tag
==
'
tr
'
:
self
.
_current_row
=
self
.
handle_current_row
(
self
.
_current_row
)
if
self
.
_current_row
:
self
.
_current_table
.
append
(
self
.
_current_row
)
self
.
_current_row
=
[]
elif
tag
==
'
table
'
:
self
.
tables
.
append
(
self
.
_current_table
)
self
.
_current_table
=
[]
def
handle_current_row
(
self
,
current_row
):
"""
Override this method for customization
"""
return
current_row
def
handle_starttag_sub
(
self
,
tag
,
attrs
):
"""
Override this method for customization
"""
pass
class
GccTableHTMLParser
(
TableHTMLParser
,
ABC
):
def
__init__
(
self
):
super
().
__init__
()
self
.
_current_cell_datetime_string
=
None
def
handle_current_row
(
self
,
current_row
):
try
:
version
=
re
.
sub
(
'
[^0-9.]
'
,
""
,
current_row
[
0
])
date_string
=
current_row
[
1
]
datetime_object
=
datetime
.
strptime
(
date_string
,
'
%B %d, %Y
'
)
return
[
version
,
datetime_object
]
except
Exception
:
return
[]
class
KernelTableHTMLParser
(
TableHTMLParser
,
ABC
):
def
__init__
(
self
):
super
().
__init__
()
self
.
_current_cell_datetime_string
=
None
def
handle_starttag_sub
(
self
,
tag
,
attrs
):
if
tag
==
'
span
'
:
for
name
,
value
in
attrs
:
if
name
==
'
title
'
:
self
.
_current_cell_datetime_string
=
value
def
handle_current_row
(
self
,
current_row
):
try
:
version
=
current_row
[
0
].
replace
(
"
-
"
,
"
.
"
)
version
=
re
.
sub
(
'
[^0-9.-]
'
,
""
,
version
)
date_string
=
self
.
_current_cell_datetime_string
.
split
(
'
'
)[
0
]
datetime_object
=
datetime
.
strptime
(
date_string
,
'
%Y-%m-%d
'
)
return
[
version
,
datetime_object
]
except
Exception
:
return
[]
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