diff --git a/web/base.py b/web/base.py index 56807a8c7..f86e6c91c 100644 --- a/web/base.py +++ b/web/base.py @@ -16,6 +16,7 @@ sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) from core.config import cfg +from web.exceptions import * __all__ = ['Request', 'get_html', 'post_html', 'request_get', 'resp2html', 'is_connectable', 'download', 'get_resp_text'] @@ -111,7 +112,10 @@ def request_get(url, cookies={}, timeout=cfg.Network.timeout, delay_raise=False) """获取指定url的原始请求""" r = requests.get(url, headers=headers, proxies=cfg.Network.proxy, cookies=cookies, timeout=timeout) if not delay_raise: - r.raise_for_status() + if r.status_code == 403 and b'>Just a moment...<' in r.content: + raise SiteBlocked(f"403 Forbidden: 无法通过CloudFlare检测: {url}") + else: + r.raise_for_status() return r @@ -140,7 +144,8 @@ def get_html(url, encoding='utf-8'): html.make_links_absolute(url, resolve_base_href=True) # 清理功能仅应在需要的时候用来调试网页(如prestige),否则可能反过来影响调试(如JavBus) # html = cleaner.clean_html(html) - # lxml.html.open_in_browser(html, encoding=encoding) # for develop and debug + if hasattr(sys, 'javsp_debug_mode'): + lxml.html.open_in_browser(html, encoding=encoding) # for develop and debug return html @@ -150,7 +155,8 @@ def resp2html(resp, encoding='utf-8') -> lxml.html.HtmlComment: html = lxml.html.fromstring(text) html.make_links_absolute(resp.url, resolve_base_href=True) # html = cleaner.clean_html(html) - # lxml.html.open_in_browser(html, encoding=encoding) # for develop and debug + if hasattr(sys, 'javsp_debug_mode'): + lxml.html.open_in_browser(html, encoding=encoding) # for develop and debug return html diff --git a/web/fc2ppvdb.py b/web/fc2ppvdb.py index 9766feb71..2751ea298 100644 --- a/web/fc2ppvdb.py +++ b/web/fc2ppvdb.py @@ -6,9 +6,8 @@ sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) -from web.base import get_html, request_get +from web.base import get_html from web.exceptions import * -from core.config import cfg from core.lib import strftime_to_minutes from core.datatype import MovieInfo