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}')