Extract a small text excerpt when the structured page cannot be parsed.
(html_text: str)
| 787 | |
| 788 | |
| 789 | def _build_scholar_fallback_excerpt(html_text: str) -> str: |
| 790 | """Extract a small text excerpt when the structured page cannot be parsed.""" |
| 791 | title = _strip_html(_extract_first_group(r"<title[^>]*>(.*?)</title>", html_text)) |
| 792 | description = _strip_html( |
| 793 | _extract_first_group( |
| 794 | r'<meta[^>]+name=["\']description["\'][^>]+content=["\'](.*?)["\']', |
| 795 | html_text, |
| 796 | ) |
| 797 | ) |
| 798 | body_excerpt = _collapse_whitespace(_strip_html(html_text))[:600] |
| 799 | return " ".join(part for part in (title, description, body_excerpt) if part).strip() |
| 800 | |
| 801 | |
| 802 | def _extract_external_homepage_url(html_text: str, base_url: str = "") -> str: |
no test coverage detected