From e9e03cd7cadf30c5d6c51b1a5f72690f54715a77 Mon Sep 17 00:00:00 2001 From: work Date: Thu, 21 Aug 2025 09:35:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E6=98=BE=E7=A4=BA=E6=AF=94?= =?UTF-8?q?=E4=BE=8B=E5=A2=9E=E5=8A=A0=E5=8F=91=E8=A7=86=E9=A2=91=E7=AD=89?= =?UTF-8?q?=E5=BE=85=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- const.py | 6 ++++-- spider/task.py | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/const.py b/const.py index b6f2f08..30efcff 100644 --- a/const.py +++ b/const.py @@ -1,4 +1,5 @@ import os + BASE_PATH = os.path.dirname(__file__) SAFE = '!' MIMETYPE = { @@ -11,7 +12,6 @@ MIMETYPE = { PIC_TYPE = ('image/jpeg', 'image/png') - ELEMENT = { } @@ -26,6 +26,8 @@ PROXY_HOST = 'http://proxy.ipipgo.com:31212' PROXY_USER = 'customer-94620c-country-US' PROXY_PASS = '4ea715cd' - api_key = "adf0d1fc9c9313b7f87c18bf9caef01d" api_url = "http://local.adspower.net:50325" + +# 显示缩放比例 1为100% +DISPLAY_SCALE = 0.7 diff --git a/spider/task.py b/spider/task.py index 2cdb6be..18d01dc 100644 --- a/spider/task.py +++ b/spider/task.py @@ -270,6 +270,7 @@ def retry_get_new_video(page, cookies, video_count): page.query_selector_all('//img[@alt="View photo"]')[0].hover() page.query_selector_all('//img[@alt="View photo"]')[0].click() page.reload() + time.sleep(random.randint(3, 5)) return page.url # 计算下一次重试时间 @@ -296,6 +297,7 @@ def playwright_post(cookies, content, image_key=None): context = browser.new_context(no_viewport=True) context.add_cookies(parse_cookies(cookies)) page = context.new_page() + page.evaluate(f'document.body.style.zoom = "{const.DISPLAY_SCALE}"') check_account_status(page, parse_cookies(cookies)) # 声明默认发布视频数量 @@ -335,6 +337,7 @@ def playwright_post(cookies, content, image_key=None): # 视频格式要单独去获取链接 if ".mp4" in image_key: post_url = retry_get_new_video(page, cookies, video_count) + time.sleep(random.randint(3, 10)) except Error as e: raise OperationFailed(f'操作超时,请重试{e}')