diff --git a/.idea/Crawler.iml b/.idea/Crawler.iml
index 77ab65d..4ba3f29 100644
--- a/.idea/Crawler.iml
+++ b/.idea/Crawler.iml
@@ -4,7 +4,7 @@
-
+
diff --git a/.idea/misc.xml b/.idea/misc.xml
index f1bf6fa..a1ff0d1 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -3,5 +3,5 @@
-
+
\ No newline at end of file
diff --git a/Apps/XinDianTu/Opener.py b/Apps/XinDianTu/Opener.py
index 1b68058..a407df5 100644
--- a/Apps/XinDianTu/Opener.py
+++ b/Apps/XinDianTu/Opener.py
@@ -8,7 +8,7 @@ import uuid
import uiautomator2 as u2
from Apps.XinDianTu.Kit import take_screenshot, detect_black_agree_button, detect_any_ad_close, \
- detect_bottom_close_circle, is_background_dimmed
+ detect_bottom_close_circle, is_background_dimmed, click_image_template
from Config.Config import TEMP_IMAGE_DIR
# pip install adbutils
@@ -19,6 +19,9 @@ logging.basicConfig(
)
logger = logging.getLogger("OpenXinDianTu")
+# 获取当前脚本所在目录
+BASE_DIR = os.path.dirname(os.path.abspath(__file__))
+
async def check_and_close_ad(d):
"""
检测并关闭广告弹窗(优先使用计算机图形学方案,节省成本和时间)
@@ -29,7 +32,6 @@ async def check_and_close_ad(d):
t1 = time.time()
image_uuid = str(uuid.uuid4())
# 使用相对路径: 基于当前脚本目录下的 Images 文件夹
- base_dir = os.path.dirname(os.path.abspath(__file__))
save_dir = TEMP_IMAGE_DIR
screenshot_path = take_screenshot(d, image_uuid, save_dir=save_dir)
logger.info(f"Step [广告检测截图] 耗时: {time.time() - t1:.4f}s")
@@ -56,7 +58,7 @@ async def check_and_close_ad(d):
return True
# 方案 B: 多模板匹配检测 "关闭(X)" 按钮 (支持多种广告样式)
- template_dir = os.path.join(base_dir, "Templates")
+ template_dir = os.path.join(BASE_DIR, "Templates")
if os.path.exists(template_dir):
logger.info(f"正在尝试多模板匹配关闭按钮: {template_dir}")
@@ -145,8 +147,21 @@ async def open_mini_program():
# 点击搜索按钮(放大镜图标)
logger.info("尝试查找并点击 '搜索按钮(放大镜图标)'...")
- d.image.click("SearchButton.jpg")
- logger.info("点击了搜索按钮(放大镜图标)")
+ search_template = os.path.join(BASE_DIR, "Templates", "SearchButton.jpg")
+ if not os.path.exists(search_template):
+ search_template = os.path.join(BASE_DIR, "SearchButton.jpg")
+
+ if click_image_template(d, search_template):
+ logger.info("点击了搜索按钮(放大镜图标)")
+ else:
+ logger.warning("未找到搜索按钮(放大镜图标),尝试兜底坐标点击...")
+ # 兜底点击:精确相对坐标:x=84%, y=8% (基于截图推算)
+ window_size = d.window_size()
+ w, h = window_size[0], window_size[1]
+ click_x = int(w * 0.84)
+ click_y = int(h * 0.08)
+ d.click(click_x, click_y)
+ logger.info(f"使用精确坐标点击搜索按钮: ({click_x}, {click_y})")
# 点击后给予一定的加载时间
await asyncio.sleep(2)
@@ -192,8 +207,16 @@ async def open_mini_program():
# 点击符合新电途图标的小程序
logger.info("尝试查找并点击 '新电途小程序'...")
- d.image.click("xdt.jpg")
- logger.info("点击了新电途的小程序")
+ xdt_template = os.path.join(BASE_DIR, "Templates", "xdt.jpg")
+ if click_image_template(d, xdt_template):
+ logger.info("点击了新电途的小程序")
+ else:
+ logger.warning("未找到新电途小程序图标,尝试坐标点击第一项...")
+ window_size = d.window_size()
+ w, h = window_size[0], window_size[1]
+ res_x, res_y = int(w * 0.5), int(h * 0.18)
+ d.click(res_x, res_y)
+ logger.info(f"坐标点击搜索结果第一项: ({res_x}, {res_y})")
await asyncio.sleep(10)
# 进入小程序后,检查并处理广告
diff --git a/SearchButton.jpg b/Apps/XinDianTu/Templates/SearchButton.jpg
similarity index 100%
rename from SearchButton.jpg
rename to Apps/XinDianTu/Templates/SearchButton.jpg
diff --git a/xdt.jpg b/Apps/XinDianTu/Templates/xdt.jpg
similarity index 100%
rename from xdt.jpg
rename to Apps/XinDianTu/Templates/xdt.jpg
diff --git a/xdt1.jpg b/Apps/XinDianTu/Templates/xdt1.jpg
similarity index 100%
rename from xdt1.jpg
rename to Apps/XinDianTu/Templates/xdt1.jpg
diff --git a/Apps/XinDianTu/__pycache__/Opener.cpython-310.pyc b/Apps/XinDianTu/__pycache__/Opener.cpython-310.pyc
index 1fa77ee..ca86a99 100644
Binary files a/Apps/XinDianTu/__pycache__/Opener.cpython-310.pyc and b/Apps/XinDianTu/__pycache__/Opener.cpython-310.pyc differ
diff --git a/Output/debug_ad_close_fail.jpg b/Output/debug_ad_close_fail.jpg
index 0a2654a..d6b68e8 100644
Binary files a/Output/debug_ad_close_fail.jpg and b/Output/debug_ad_close_fail.jpg differ