Extract lightweight Scholar metadata from a profile page.
(html_text: str)
| 819 | for item in top_cited_publications |
| 820 | if str(item.get("title") or "").strip() |
| 821 | ], |
| 822 | } |
| 823 | |
| 824 | |
| 825 | def _is_probable_scholar_block_page(html_text: str) -> bool: |
| 826 | """Detect common anti-bot / captcha pages returned by Scholar.""" |
| 827 | normalized = (html_text or "").casefold() |
| 828 | block_markers = ( |
| 829 | "unusual traffic", |
| 830 | "not a robot", |
| 831 | "detected unusual traffic", |
| 832 | "sorry...", |
| 833 | "captcha", |
| 834 | "/sorry/", |
| 835 | "recaptcha", |
| 836 | ) |
| 837 | return any(marker in normalized for marker in block_markers) |
| 838 | |
| 839 | |
| 840 | def _build_scholar_fallback_excerpt(html_text: str) -> str: |
| 841 | """Extract a small text excerpt when the structured page cannot be parsed.""" |
| 842 | title = _strip_html(_extract_first_group(r"<title[^>]*>(.*?)</title>", html_text)) |
| 843 | description = _strip_html( |
| 844 | _extract_first_group( |
| 845 | r'<meta[^>]+name=["\']description["\'][^>]+content=["\'](.*?)["\']', |
| 846 | html_text, |
| 847 | ) |
| 848 | ) |
| 849 | body_excerpt = _collapse_whitespace(_strip_html(html_text))[:600] |
| 850 | return " ".join(part for part in (title, description, body_excerpt) if part).strip() |
| 851 | |
| 852 | |
| 853 | def _extract_external_homepage_url(html_text: str, base_url: str = "") -> str: |
| 854 | """Return the first plausible external homepage URL from an HTML page.""" |
| 855 | for match in re.finditer(r'<a\b[^>]*href=["\'](.*?)["\']', html_text or "", re.IGNORECASE | re.DOTALL): |
| 856 | raw_href = html.unescape(_collapse_whitespace(match.group(1))) |
| 857 | if not raw_href: |
| 858 | continue |
| 859 | resolved = urljoin(base_url or "", raw_href) |
| 860 | parsed = urlsplit(resolved) |
| 861 | if parsed.scheme not in {"http", "https"}: |
| 862 | continue |
| 863 | netloc = (parsed.netloc or "").casefold() |
| 864 | if not netloc or "scholar.google." in netloc or "google." == netloc: |
| 865 | continue |
| 866 | if any(token in resolved.casefold() for token in ("/citations?", "/scholar?", "view_op=")): |
| 867 | continue |
| 868 | return resolved |
| 869 | return "" |
| 870 | |
| 871 | |
| 872 | def _parse_google_scholar_profile_html(html_text: str) -> Dict[str, Any]: |
| 873 | """Extract lightweight Scholar metadata from a profile page.""" |
| 874 | name = _strip_html(_extract_first_group(r'<div[^>]*id=["\']gsc_prf_in["\'][^>]*>(.*?)</div>', html_text)) |
| 875 | affiliation = _strip_html( |
| 876 | _extract_first_group(r'<div[^>]*class=["\'][^"\']*\bgsc_prf_il\b[^"\']*["\'][^>]*>(.*?)</div>', html_text) |
| 877 | ) |
| 878 |
no test coverage detected