'commit'
2
.idea/Crawler.iml
generated
@@ -4,7 +4,7 @@
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Python 3.12" jdkType="Python SDK" />
|
||||
<orderEntry type="jdk" jdkName="D:\anaconda3\envs\py310" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
<component name="PyDocumentationSettings">
|
||||
|
||||
2
.idea/misc.xml
generated
@@ -3,5 +3,5 @@
|
||||
<component name="Black">
|
||||
<option name="sdkName" value="Python 3.12" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12" project-jdk-type="Python SDK" />
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="D:\anaconda3\envs\py310" project-jdk-type="Python SDK" />
|
||||
</project>
|
||||
@@ -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)
|
||||
# 进入小程序后,检查并处理广告
|
||||
|
||||
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 296 KiB After Width: | Height: | Size: 231 KiB |