提交 aa1e04bd 编写于 作者: Q qq_38870145

Tue Apr 1 19:58:00 CST 2025 inscode

上级 04e2a310
import time,math import time,math
from selenium import webdriver from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support import expected_conditions as EC
...@@ -44,11 +41,6 @@ def cut_img(screenshot_path,element,baseDir,loc): ...@@ -44,11 +41,6 @@ def cut_img(screenshot_path,element,baseDir,loc):
def screen_shot(driver): def screen_shot(driver):
dir=gen_dir() dir=gen_dir()
# global cut_img_paths
# cut_img_paths=[]
# global full_img_paths
# full_img_paths=[]
# 当前滚动高度 # 当前滚动高度
scrollTop=driver.execute_script( scrollTop=driver.execute_script(
'return document.getElementById("ConversationReadingPaneContainer").childNodes[1].childNodes[0].scrollTop;') 'return document.getElementById("ConversationReadingPaneContainer").childNodes[1].childNodes[0].scrollTop;')
...@@ -81,6 +73,12 @@ def screen_shot(driver): ...@@ -81,6 +73,12 @@ def screen_shot(driver):
full_img_paths.append(img_path) full_img_paths.append(img_path)
# 滚动底部 + 渲染高度 翻页滚动 # 滚动底部 + 渲染高度 翻页滚动
while math.ceil(lastScrollTop+1) < scrollHeight: while math.ceil(lastScrollTop+1) < scrollHeight:
end_rect_top = driver.execute_script('return document.querySelector(".g4Y3U").getBoundingClientRect().top;')
sleep(.5)
# end 结束 节点出现在可视区域 dom rect top<window height
if end_rect_top < window_height:
break
i += 1 i += 1
# 加渲染高度 翻页 好拼接 # 加渲染高度 翻页 好拼接
lastScrollTop += clientHeight lastScrollTop += clientHeight
...@@ -92,33 +90,12 @@ def screen_shot(driver): ...@@ -92,33 +90,12 @@ def screen_shot(driver):
driver.save_screenshot(img_path) driver.save_screenshot(img_path)
cut_img(img_path, element, dir, i) cut_img(img_path, element, dir, i)
full_img_paths.append(img_path) full_img_paths.append(img_path)
end_rect_bottom = driver.execute_script(
'return document.querySelector(".T_6Xj").getBoundingClientRect().bottom;')
end_rect_top = driver.execute_script('return document.querySelector(".T_6Xj").getBoundingClientRect().top;')
# end
if end_rect_top < window_height and end_rect_bottom > 0:
break
else: else:
# 完整email # 完整email
img_path=f'{dir}/full_screen_email.png' img_path=f'{dir}/full_screen_email.png'
driver.save_screenshot(img_path) driver.save_screenshot(img_path)
cut_len=len(cut_img_paths)
first=0
second=1
print('cut_img_paths',cut_img_paths)
print('cut_len',cut_len)
# while second<cut_len:
# gen_img_path = f'{dir}/temp_result_{i}.png'
# if first ==0:
# img1_path=cut_img_paths[first]
# else:
# img1_path= gen_img_path
# join_images(img1_path,cut_img_paths[second],0,gen_img_path)
# second += 1
# print('second',second)
# 裁剪顶部高度 渲染高度 # 裁剪顶部高度 渲染高度
crop_height=driver.execute_script('return document.getElementById("ConversationReadingPaneContainer").firstChild.offsetHeight;') crop_height=driver.execute_script('return document.getElementById("ConversationReadingPaneContainer").firstChild.offsetHeight;')
# 8px padding # 8px padding
...@@ -248,7 +225,7 @@ def mapMSg(): ...@@ -248,7 +225,7 @@ def mapMSg():
break break
time.sleep(1) time.sleep(1)
driver.quit() driver.quit()
time.sleep(50) time.sleep(3)
driver.close() driver.close()
if __name__ == '__main__': if __name__ == '__main__':
run() run()
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册