summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorluke@maurits.id.au <luke@maurits.id.au@0f58610c-415a-11de-9c03-5d6cfad8e937>2013-10-07 21:06:06 +0000
committerluke@maurits.id.au <luke@maurits.id.au@0f58610c-415a-11de-9c03-5d6cfad8e937>2013-10-07 21:06:06 +0000
commitf80bf107fef6bbed80efb6011e8def5b0fcd4be2 (patch)
tree35dd430389cd21c60c639edc160d74d01ed2775b
parent7a3fd33c87fc5acdd971dd618439d3bed892cfcc (diff)
downloadpython-prettytable-f80bf107fef6bbed80efb6011e8def5b0fcd4be2.tar.gz
Handle colspan in from_html.
git-svn-id: http://prettytable.googlecode.com/svn/trunk@142 0f58610c-415a-11de-9c03-5d6cfad8e937
-rw-r--r--CHANGELOG2
-rw-r--r--prettytable.py10
2 files changed, 12 insertions, 0 deletions
diff --git a/CHANGELOG b/CHANGELOG
index e49acfc..b68925b 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,5 +1,7 @@
########## PrettyTable 0.8 - Oct XX, 2013 ###########
+* from_html now handles HTML tables with colspan, rather than
+ choking on them.
* Added "min_width", "min_table_width" and "max_table_width"
attribute/options for better control of table sizing.
* Added "title" attribute/option for table titles.
diff --git a/prettytable.py b/prettytable.py
index 5bb4365..38bf75a 100644
--- a/prettytable.py
+++ b/prettytable.py
@@ -1551,16 +1551,26 @@ class TableHandler(HTMLParser):
self.active = None
self.last_content = ""
self.is_last_row_header = False
+ self.colspan = 0
def handle_starttag(self,tag, attrs):
self.active = tag
if tag == "th":
self.is_last_row_header = True
+ for (key, value) in attrs:
+ if key == "colspan":
+ self.colspan = int(value)
+
def handle_endtag(self,tag):
if tag in ["th", "td"]:
stripped_content = self.last_content.strip()
self.last_row.append(stripped_content)
+ if self.colspan:
+ for i in range(1, self.colspan):
+ self.last_row.append("")
+ self.colspan = 0
+
if tag == "tr":
self.rows.append(
(self.last_row, self.is_last_row_header))