mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-08-07 22:23:48 +08:00
fix(lxml): Adjust HTML element checks to prevent FutureWarning
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
from lxml import etree
|
||||
|
||||
from app.utils.string import StringUtils
|
||||
|
||||
|
||||
class SiteUtils:
|
||||
|
||||
@@ -11,7 +13,7 @@ class SiteUtils:
|
||||
:return:
|
||||
"""
|
||||
html = etree.HTML(html_text)
|
||||
if not html:
|
||||
if not StringUtils.is_valid_html_element(html):
|
||||
return False
|
||||
# 存在明显的密码输入框,说明未登录
|
||||
if html.xpath("//input[@type='password']"):
|
||||
@@ -39,7 +41,7 @@ class SiteUtils:
|
||||
:return True已签到 False未签到
|
||||
"""
|
||||
html = etree.HTML(html_text)
|
||||
if not html:
|
||||
if not StringUtils.is_valid_html_element(html):
|
||||
return False
|
||||
# 站点签到支持的识别XPATH
|
||||
xpaths = [
|
||||
|
||||
@@ -795,3 +795,13 @@ class StringUtils:
|
||||
:return: 如果输入值不是 None,返回去除空白字符后的字符串,否则返回 None
|
||||
"""
|
||||
return value.strip() if value is not None else None
|
||||
|
||||
@staticmethod
|
||||
def is_valid_html_element(elem) -> bool:
|
||||
"""
|
||||
检查elem是否为有效的HTML元素。元素必须为非None并且具有非零长度。
|
||||
|
||||
:param elem: 要检查的HTML元素
|
||||
:return: 如果elem有效(非None且长度大于0),返回True;否则返回False
|
||||
"""
|
||||
return elem is not None and len(elem) > 0
|
||||
|
||||
Reference in New Issue
Block a user