Fix SelectorSyntaxError import: use Exception catch with message check, 18/18 tests passing
This commit is contained in:
@@ -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}"
|
||||
|
||||
Reference in New Issue
Block a user