summaryrefslogtreecommitdiff
path: root/examples/htmlTableParser.py
diff options
context:
space:
mode:
authorPaul McGuire <ptmcg@austin.rr.com>2019-04-06 23:44:02 -0500
committerPaul McGuire <ptmcg@austin.rr.com>2019-04-06 23:44:02 -0500
commita2439508ba5c94546db98593cfa676de9b59babe (patch)
tree80b02178820811c09b4befc9a9b5efb092813466 /examples/htmlTableParser.py
parent832986ffccac943b363da43795c335eafc31b5da (diff)
downloadpyparsing-git-a2439508ba5c94546db98593cfa676de9b59babe.tar.gz
Fixed dict structure in makeHTMLTags expressions, and added tag_body attribute to the generated start expression giving easy access to a SkipTo(closeTag) that will parse the tag's body text; some code cleanup and removed duplication among examples
Diffstat (limited to 'examples/htmlTableParser.py')
-rw-r--r--examples/htmlTableParser.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/examples/htmlTableParser.py b/examples/htmlTableParser.py
index 5fe8e5f..35cdd03 100644
--- a/examples/htmlTableParser.py
+++ b/examples/htmlTableParser.py
@@ -23,12 +23,12 @@ a, a_end = pp.makeHTMLTags('a')
strip_html = (pp.anyOpenTag | pp.anyCloseTag).suppress().transformString
# expression for parsing <a href="url">text</a> links, returning a (text, url) tuple
-link = pp.Group(a + pp.SkipTo(a_end)('text') + a_end.suppress())
+link = pp.Group(a + a.tag_body('text') + a_end.suppress())
link.addParseAction(lambda t: (t[0].text, t[0].href))
# method to create table rows of header and data tags
def table_row(start_tag, end_tag):
- body = pp.SkipTo(end_tag)
+ body = start_tag.tag_body
body.addParseAction(pp.tokenMap(str.strip),
pp.tokenMap(strip_html))
row = pp.Group(tr.suppress()