diff --git a/app/services/domains/scholar/profile_rows.py b/app/services/domains/scholar/profile_rows.py index 4ae3bc4..6a63274 100644 --- a/app/services/domains/scholar/profile_rows.py +++ b/app/services/domains/scholar/profile_rows.py @@ -106,15 +106,13 @@ def parse_cluster_id_from_href(href: str | None) -> str | None: if citation_for_view: token = citation_for_view[0].strip() if token: - if ":" in token: - return token.rsplit(":", 1)[-1] or None - return token + return f"cfv:{token}" cluster = query.get("cluster") if cluster: token = cluster[0].strip() if token: - return token + return f"cluster:{token}" return None @@ -133,10 +131,10 @@ def parse_citation_count(parts: list[str]) -> int | None: text = normalize_space(" ".join(parts)) if not text: return 0 - match = re.search(r"\d+", text) - if not match: + digits = re.sub(r"\D+", "", text) + if not digits: return None - return int(match.group(0)) + return int(digits) def _parse_publication_row(row_html: str) -> tuple[PublicationCandidate | None, list[str]]: diff --git a/tests/unit/test_scholar_parser.py b/tests/unit/test_scholar_parser.py index f684f7b..7c70dd3 100644 --- a/tests/unit/test_scholar_parser.py +++ b/tests/unit/test_scholar_parser.py @@ -97,10 +97,44 @@ def test_parse_profile_page_handles_missing_optional_metadata() -> None: assert parsed.state_reason == "publications_extracted" assert len(parsed.publications) == 1 publication = parsed.publications[0] + assert publication.cluster_id == "cfv:abc:def123" assert publication.year is None assert publication.venue_text is None +def test_parse_profile_page_parses_comma_formatted_citation_counts() -> None: + html = """ + +
Citation Formatting Test
+ Articles 1-1 + + + + + + + + +
+ Paper + Cited by 1,2342024
+ + """ + fetch_result = FetchResult( + requested_url="https://scholar.google.com/citations?hl=en&user=abcDEF123456", + status_code=200, + final_url="https://scholar.google.com/citations?hl=en&user=abcDEF123456", + body=html, + error=None, + ) + + parsed = parse_profile_page(fetch_result) + + assert parsed.state == ParseState.OK + assert len(parsed.publications) == 1 + assert parsed.publications[0].citation_count == 1234 + + def test_parse_profile_page_ignores_direct_pdf_link_markup() -> None: html = """