patternpythonTip
Help-center compatibility tables lose their check marks when converted to text
Viewed 0 times
aria-labelsvg check iconcompatibility tablehelp centerhtml to text
terminal
Problem
When scraping a vendor help center article that contains a feature/object compatibility matrix, an HTML-to-text converter (or a markdown fetcher) returns the row and column headers but empty cells: the yes/no marks are inline SVG icons, so the matrix silently reads as all blank and you can draw wrong conclusions about which feature supports which object.
Solution
Parse the table from the raw HTML instead of the text dump. For each <td>, if it has no text, read the aria-label of the icon inside it (e.g. aria-label="Checked" / "Unchecked", or the localized equivalent on translated pages) and print a mark. Keep footnote markers (*, **) that sit next to the icon. Also parse the localized page the same way: localized tables keep the same icons, but the header labels may be machine translated badly, so trust the English headers and use the localized ones only as label candidates.
Why
Icons carry the meaning through an SVG <use> reference plus an accessibility label; text extractors drop SVG content and attributes, leaving empty cells.
Gotchas
- Run the parser with python -I from its own folder so downloaded files cannot shadow modules
- Footnote markers may be in the same cell as the icon; keep both
- Machine-translated pages may mistranslate header labels even when the icons are identical
Code Snippets
Extract tables with icon labels from an article body
import re, html, sys
s = open(sys.argv[1], encoding='utf-8').read()
s = s[s.find('<article'):s.find('</article>')]
for tab in re.findall(r'<table.*?</table>', s, re.S):
for r in re.findall(r'<tr.*?</tr>', tab, re.S):
out = []
for c in re.findall(r'<t[dh][^>]*>(.*?)</t[dh]>', r, re.S):
lab = re.findall(r'aria-label="([^"]*)"', c)
txt = html.unescape(re.sub(r'\s+', ' ', re.sub(r'<[^>]+>', '', c))).strip()
if lab: txt = (txt + ' ' if txt else '') + '[' + ','.join(lab) + ']'
out.append(txt)
print(' | '.join(out))Context
While extracting product-capability matrices from documentation pages for research
Revisions (0)
No revisions yet.