"""Print a news page's dates, title and paragraph text, read as data (no scripts run). usage: python3 -I article_text.py [max chars]""" import sys, re, html, json sys.stdout.reconfigure(encoding="utf-8") s = open(sys.argv[1], "rb").read().decode("utf-8", "replace") lim = int(sys.argv[2]) if len(sys.argv) > 2 else 6000 for pat in (r']+(?:property|name|itemprop)="(article:published_time|article:modified_time|og:title|og:description|datePublished|dateModified|publish-date|date|og:updated_time)"[^>]+content="([^"]*)"', r']+content="([^"]*)"[^>]+(?:property|name|itemprop)="(article:published_time|article:modified_time|og:title|datePublished)"'): for m in re.finditer(pat, s, re.I): print("META", m.group(1), "=", html.unescape(m.group(2))[:300]) for m in re.finditer(r'"(datePublished|dateModified|uploadDate)"\s*:\s*"([^"]+)"', s): print("JSONLD", m.group(1), "=", m.group(2)) for m in re.finditer(r"", s, re.I | re.S): print("TIME", m.group(1), "|", re.sub(r"<[^>]+>", "", m.group(2)).strip()[:80]) t = re.search(r"