MCPcopy Create free account
hub / github.com/OpenRaiser/PaperFlow / _parse_google_scholar_profile_html

Function _parse_google_scholar_profile_html

agents/coldstart-agent/main.py:821–897  ·  view source on GitHub ↗

Extract lightweight Scholar metadata from a profile page.

(html_text: str)

Source from the content-addressed store, hash-verified

819
820
821def _parse_google_scholar_profile_html(html_text: str) -> Dict[str, Any]:
822 """Extract lightweight Scholar metadata from a profile page."""
823 name = _strip_html(_extract_first_group(r'<div[^>]*id=["\']gsc_prf_in["\'][^>]*>(.*?)</div>', html_text))
824 affiliation = _strip_html(
825 _extract_first_group(r'<div[^>]*class=["\'][^"\']*\bgsc_prf_il\b[^"\']*["\'][^>]*>(.*?)</div>&#x27;, html_text)
826 )
827
828 interests_block = _extract_first_group(r'<div[^>]*id=["\']gsc_prf_int["\'][^>]*>(.*?)</div>', html_text)
829 interests = [
830 interest
831 for interest in (
832 _strip_html(match.group(1))
833 for match in re.finditer(r"<a\b[^>]*>(.*?)</a>", interests_block or "", re.IGNORECASE | re.DOTALL)
834 )
835 if interest
836 ]
837
838 publications: List[Dict[str, Any]] = []
839 row_pattern = r'<tr[^>]*class=["\'][^"\']*\bgsc_a_tr\b[^"\']*["\'][^>]*>(.*?)</tr>&#x27;
840 for row_match in re.finditer(row_pattern, html_text or "", re.IGNORECASE | re.DOTALL):
841 row_html = row_match.group(1)
842 title = _strip_html(
843 _extract_first_group(r'<a[^>]*class=["\'][^"\']*\bgsc_a_at\b[^"\']*["\'][^>]*>(.*?)</a>&#x27;, row_html)
844 )
845 if not title:
846 continue
847
848 gray_blocks = [
849 _strip_html(block.group(1))
850 for block in re.finditer(
851 r'<div[^>]*class=["\'][^"\']*\bgs_gray\b[^"\']*["\'][^>]*>(.*?)</div>&#x27;,
852 row_html,
853 re.IGNORECASE | re.DOTALL,
854 )
855 ]
856 citations_text = _strip_html(
857 _extract_first_group(r'<a[^>]*class=["\'][^"\']*\bgsc_a_ac\b[^"\']*["\'][^>]*>(.*?)</a>&#x27;, row_html)
858 )
859 year_block = _extract_first_group(r'<td[^>]*class=["\'][^"\']*\bgsc_a_y\b[^"\']*["\'][^>]*>(.*?)</td>&#x27;, row_html)
860 citations_match = re.search(r"\d+", citations_text)
861 year_match = re.search(r"\b(19|20)\d{2}\b", _strip_html(year_block))
862
863 publications.append(
864 {
865 "title": title,
866 "authors": gray_blocks[0] if gray_blocks else "",
867 "venue": gray_blocks[1] if len(gray_blocks) > 1 else "",
868 "citations": int(citations_match.group(0)) if citations_match else 0,
869 "year": int(year_match.group(0)) if year_match else None,
870 }
871 )
872
873 publications.sort(
874 key=lambda item: (
875 int(item.get("citations") or 0),
876 int(item.get("year") or 0),
877 len(str(item.get("title") or "")),
878 ),

Callers 1

Calls 8

_extract_first_groupFunction · 0.85
_parse_scholar_statsFunction · 0.85
getMethod · 0.80
_strip_htmlFunction · 0.70
_get_env_intFunction · 0.70

Tested by

no test coverage detected