From 843bc7c4200e7d673fa64ecb813460da0af37e5f Mon Sep 17 00:00:00 2001 From: g1879 Date: Mon, 7 Dec 2020 14:39:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E9=99=A4cssselect=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrissionPage/session_element.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/DrissionPage/session_element.py b/DrissionPage/session_element.py index 793a3cd..660c33b 100644 --- a/DrissionPage/session_element.py +++ b/DrissionPage/session_element.py @@ -8,8 +8,7 @@ import re from typing import Union, List, Tuple from urllib.parse import urlparse, urljoin, urlunparse -from cssselect import SelectorSyntaxError -from lxml.etree import tostring, XPathEvalError +from lxml.etree import tostring from lxml.html import HtmlElement, fromstring from .common import DrissionElement, str_to_loc, translate_loc, format_html @@ -383,8 +382,11 @@ def execute_session_find(page_or_ele, elif mode == 'all': return [SessionElement(e, page) if isinstance(e, HtmlElement) else e for e in ele if e != '\n'] - except XPathEvalError: - raise SyntaxError(f'Invalid xpath syntax. {loc}') + except Exception as e: - except SelectorSyntaxError: - raise SyntaxError(f'Invalid css selector syntax. {loc}') + if 'Invalid expression' in str(e): + raise SyntaxError(f'Invalid xpath syntax. {loc}') + elif 'Expected selector' in str(e): + raise SyntaxError(f'Invalid css selector syntax. {loc}') + + raise e