From 4167e15ed9411578c9f04b3748c6bb8bc21e4655 Mon Sep 17 00:00:00 2001 From: Patrick Plate Date: Fri, 3 Apr 2026 13:52:15 +0200 Subject: [PATCH] Fix SelectorSyntaxError import: use Exception catch with message check, 18/18 tests passing --- webscraper/.coverage | Bin 0 -> 53248 bytes webscraper/coverage.xml | 122 +++++++++++++++++++++++---------------- webscraper/src/server.py | 8 ++- 3 files changed, 77 insertions(+), 53 deletions(-) create mode 100644 webscraper/.coverage diff --git a/webscraper/.coverage b/webscraper/.coverage new file mode 100644 index 0000000000000000000000000000000000000000..6ca47e48ce3ab29dbb207f19280004725357bb9e GIT binary patch literal 53248 zcmeI)&2QUe90zba?vgo8abX&vRHM%U)KyE9WfS7<00k;Bm;{4@kdW{k=SgA~+nMdG ztpq|HlZN0w*!T}PbK%N?3!HY~x)bbxc+tiIwgbP%j~ypnGxfA-$v0|J$9|s2&+qfR z#Yvm@&YX54&RTxpS`j;`%qyy@yuz5GC_3He=$_sRv@w%Dq2KDz_P9-5sebj?obiED z%73UBAJ08$td`oPzh}QGJ+Hq%>l7+_l@8zr0SG_<0uv*!bEZ@%FD$4RKZ~qJmq&qR z^FTh%z4q?<+QvHDSbO#KI+Od@(ITVU>MC1ffxpRmJYX%S%bDXf9ovc=ug#(kPgD0p z-V|#V?W0voB&^2y#g^$bDObeXR75XuTr1dS=lFIdPLP}};#-m2L4|Oq?THlZXp((} z1-!)r?%6z)wK(cDSBfiNd|oV+4;@l3^Ef6eu<2)ZBpTY0g>tGz1=)Vk6t!;zmS=Z( zSYg&6LffZ$ZbdTMz;|nr&$^Bmhv|h*v3I ze&ol`O=^6zP7kF^j~*Qv zWqvCjG9ovVjYGY8c+AvN3@Z==jrmDJs_6smZKASN2iEBNjnTdq_n45=0HL`cP1fpr zwiqg*h{5(R@W5*GYI0Og3lF*@QP-*K`SSYGxUMtk0%m=%S=?F37s`u^>P0>7MoDWW zzX~H=C~e6-rqT3}%dM~*6tgX+9TM z`AaRcAU#Viyqvxe_?x#h{VfpVM*>6}i; z;yT>DD!rVQ5pIhz+837NI;D$?nC3TV(52&xHeA>8n#p=4mSI^c&HZ9P|ly z!E$mkLwY6PT4}7w)7(hU+I2ANWN*_fO)rs#JC^_-G89kc8N`ezo4q0F(p1R{q~eOW zz*mji3jN>)0SG_<0uX=z1Rwwb2tWV=5P-ns3216gEr{#?oN-+-{-6ikAOHafKmY;| zfB*y_009U<00IzrCY=>1zvWJ;!wIURc}YjnED(`i`Vp7}&Lt z2Xrw{Uzl)0)s%Dl$zhs~=R~GSdF1E+R~6%D8~G^UvK_)^UoiYr+$Cp zy8E^I>Er4Fbw<}8$;UXd0SG_<0uX=z s1Rwwb2tWV=( - + /home/pplate/pi_mcps/webscraper/src - + @@ -14,7 +14,7 @@ - + @@ -29,28 +29,28 @@ - - + + + - - - - - - - + + + + + + + - - + - - - + + + @@ -69,68 +69,90 @@ + - - - - - - - - + + + + + + + + + + + - + + + + + + + - + - - - - - - - - - + + + + + - - - + + + + - - - - - + + + + + + + - + - + - - - - + + + + + + + + + + + + + + + + + diff --git a/webscraper/src/server.py b/webscraper/src/server.py index 8432af5..476a637 100644 --- a/webscraper/src/server.py +++ b/webscraper/src/server.py @@ -1,7 +1,7 @@ """Webscraper MCP server — fetch web pages, extract content, links, tables, sitemaps.""" import httpx -from bs4 import BeautifulSoup, SelectorSyntaxError +from bs4 import BeautifulSoup from html2text import html2text from urllib.parse import urljoin from typing import List, Dict, Tuple @@ -170,8 +170,10 @@ def webscraper_fetch_section(url: str, selector: str) -> str: _, soup = _fetch_page(url) try: section = soup.select_one(selector) - except SelectorSyntaxError: - return f"Invalid CSS selector '{selector}' on {url}" + except Exception as e: + if "selector" in str(e).lower(): + return f"Invalid CSS selector '{selector}' on {url}" + raise if not section: return f"No element found for selector '{selector}' on {url}"