Skip to content

Commit

Permalink
为Cloudflare拦截导致的失败请求给出提示
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuukiy committed Sep 22, 2024
1 parent e44f58d commit 7ad4f18
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
12 changes: 9 additions & 3 deletions web/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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


Expand All @@ -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


Expand Down
3 changes: 1 addition & 2 deletions web/fc2ppvdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 7ad4f18

Please sign in to comment.