Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
yma16
auto_python
提交
04e2a310
A
auto_python
项目概览
yma16
/
auto_python
与 Fork 源项目一致
Fork自
inscode / Python
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
auto_python
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
04e2a310
编写于
4月 01, 2025
作者:
Q
qq_38870145
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Tue Apr 1 18:47:00 CST 2025 inscode
上级
efc92edc
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
148 addition
and
84 deletion
+148
-84
outlook.py
outlook.py
+148
-84
未找到文件。
outlook.py
浏览文件 @
04e2a310
...
...
@@ -11,14 +11,18 @@ import os
from
PIL
import
Image
from
time
import
sleep
def
genDir
():
# cut
cut_img_paths
=
[]
# full
full_img_paths
=
[]
def
gen_dir
():
cur_timestemp
=
int
(
round
(
time
.
time
()
*
1000
))
dir
=
'./screen_shot/outlook/{ts}'
.
format
(
ts
=
cur_timestemp
)
os
.
makedirs
(
dir
,
exist_ok
=
True
)
return
dir
def
cut
I
mg
(
screenshot_path
,
element
,
baseDir
,
loc
):
def
cut
_i
mg
(
screenshot_path
,
element
,
baseDir
,
loc
):
# 获取元素坐标和尺寸
location
=
element
.
location
# {x: number, y: number}
size
=
element
.
size
# {width: number, height: number}
...
...
@@ -32,87 +36,148 @@ def cutImg(screenshot_path,element,baseDir,loc):
# 使用 Pillow 裁剪图像
image
=
Image
.
open
(
screenshot_path
)
cropped_image
=
image
.
crop
((
left
,
top
,
right
,
bottom
))
cropped_image
.
save
(
f
"
{
baseDir
}
/cut_
{
loc
}
.png"
)
class
ScreenShot
:
__JS__
=
{
'scroll_to_bottom'
:
"window.scroll({top:document.body.clientHeight,left:0,behavior:'auto'});"
,
'scroll_to_y'
:
"window.scroll({top:%d,left:0,behavior:'auto'});"
,
}
__base_end__
=
'tmp_end.png'
__scroll_bottom__
=
'scroll_to_bottom'
__scroll_y__
=
'scroll_to_y'
__body__
=
'//body'
__height__
=
'height'
__clear_shell__
=
'rm -rf *.png'
__RGB__
=
'RGB'
@
classmethod
def
screen_shot
(
cls
,
driver
,
title
,
uploader_url
=
''
,
delete
=
False
):
dir
=
genDir
()
# 当前滚动高度
scrollTop
=
driver
.
execute_script
(
'return document.getElementById("ConversationReadingPaneContainer").childNodes[1].childNodes[0].scrollTop;'
)
# 可滚动高度范围
scrollHeight
=
driver
.
execute_script
(
'return document.getElementById("ConversationReadingPaneContainer").childNodes[1].childNodes[0].scrollHeight;'
)
# 渲染的可视区域
clientHeight
=
driver
.
execute_script
(
'return document.getElementById("ConversationReadingPaneContainer").childNodes[1].childNodes[0].clientHeight;'
)
print
(
'scrollTop'
,
scrollTop
,
type
(
scrollTop
))
print
(
'scrollHeight'
,
scrollHeight
)
print
(
'clientHeight'
,
clientHeight
)
lastScrollTop
=
scrollTop
# 次数索引
i
=
0
# 等待元素加载并可见
element
=
WebDriverWait
(
driver
,
10
).
until
(
EC
.
visibility_of_element_located
((
By
.
ID
,
"ConversationReadingPaneContainer"
))
)
if
lastScrollTop
<
scrollHeight
:
img_path
=
f
'
{
dir
}
/custom_
{
i
}
.png'
cut_file_name
=
f
"
{
baseDir
}
/cut_
{
loc
}
.png"
cropped_image
.
save
(
cut_file_name
)
global
cut_img_paths
cut_img_paths
.
append
(
cut_file_name
)
def
screen_shot
(
driver
):
dir
=
gen_dir
()
# global cut_img_paths
# cut_img_paths=[]
# global full_img_paths
# full_img_paths=[]
# 当前滚动高度
scrollTop
=
driver
.
execute_script
(
'return document.getElementById("ConversationReadingPaneContainer").childNodes[1].childNodes[0].scrollTop;'
)
# 可滚动高度范围
scrollHeight
=
driver
.
execute_script
(
'return document.getElementById("ConversationReadingPaneContainer").childNodes[1].childNodes[0].scrollHeight;'
)
# 渲染的可视区域
clientHeight
=
driver
.
execute_script
(
'return document.getElementById("ConversationReadingPaneContainer").childNodes[1].childNodes[0].clientHeight;'
)
print
(
'scrollTop'
,
scrollTop
,
type
(
scrollTop
))
print
(
'scrollHeight'
,
scrollHeight
)
print
(
'clientHeight'
,
clientHeight
)
lastScrollTop
=
scrollTop
# 次数索引
i
=
0
# 等待元素加载并可见
element
=
WebDriverWait
(
driver
,
10
).
until
(
EC
.
visibility_of_element_located
((
By
.
ID
,
"ConversationReadingPaneContainer"
))
)
window_height
=
driver
.
execute_script
(
'return window.innerHeight;'
)
if
lastScrollTop
<
scrollHeight
:
img_path
=
f
'
{
dir
}
/custom_
{
i
}
.png'
driver
.
save_screenshot
(
img_path
)
cut_img
(
img_path
,
element
,
dir
,
i
)
full_img_paths
.
append
(
img_path
)
# 滚动底部 + 渲染高度 翻页滚动
while
math
.
ceil
(
lastScrollTop
+
1
)
<
scrollHeight
:
i
+=
1
# 加渲染高度 翻页 好拼接
lastScrollTop
+=
clientHeight
driver
.
execute_script
(
'document.getElementById("ConversationReadingPaneContainer").childNodes[1].childNodes[0].scrollTop={scrollTop}'
.
format
(
scrollTop
=
lastScrollTop
))
sleep
(.
5
)
img_path
=
f
'
{
dir
}
/custom_
{
i
}
.png'
driver
.
save_screenshot
(
img_path
)
cutImg
(
img_path
,
element
,
dir
,
i
)
# 滚动底部 + 渲染高度 翻页滚动
while
lastScrollTop
<
scrollHeight
:
i
+=
1
# 加渲染高度 翻页 好拼接
lastScrollTop
+=
clientHeight
driver
.
execute_script
(
'document.getElementById("ConversationReadingPaneContainer").childNodes[1].childNodes[0].scrollTop={scrollTop}'
.
format
(
scrollTop
=
lastScrollTop
))
sleep
(.
5
)
img_path
=
f
'
{
dir
}
/custom_
{
i
}
.png'
driver
.
save_screenshot
(
img_path
)
cutImg
(
img_path
,
element
,
dir
,
i
)
else
:
# 完整email
img_path
=
f
'
{
dir
}
/full_screen_email.png'
driver
.
save_screenshot
(
img_path
)
@
classmethod
def
__join_images__
(
cls
,
png1
,
png2
,
size
=
0
,
output
=
'result.png'
):
"""
图片拼接
:param png1: 图片1
:param png2: 图片2
:param size: 两个图片重叠的距离
:param output: 输出的图片文件
:return:
"""
size
=
size
*
2
img1
,
img2
=
Image
.
open
(
png1
),
Image
.
open
(
png2
)
size1
,
size2
=
img1
.
size
,
img2
.
size
joint
=
Image
.
new
(
cls
.
__RGB__
,
(
size1
[
0
],
size1
[
1
]
+
size2
[
1
]
-
size
))
loc1
,
loc2
=
(
0
,
0
),
(
0
,
size1
[
1
]
-
size
)
joint
.
paste
(
img1
,
loc1
)
joint
.
paste
(
img2
,
loc2
)
joint
.
save
(
output
)
cut_img
(
img_path
,
element
,
dir
,
i
)
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
:
# 完整email
img_path
=
f
'
{
dir
}
/full_screen_email.png'
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;'
)
# 8px padding
vertical_concatenate_with_crop
(
cut_img_paths
,
f
'
{
dir
}
/result_email.png'
,
crop_height
+
16
)
def
vertical_concatenate_with_crop
(
image_paths
,
output_path
,
crop_height
=
100
):
"""
纵向拼接多图,并对第二张图裁剪指定高度
:param image_paths: 图片路径列表(按顺序从上到下)
:param output_path: 输出文件路径
:param crop_height: 第二张图裁剪的高度(默认 100px)
"""
images
=
[]
# 读取并处理图片
for
idx
,
path
in
enumerate
(
image_paths
):
img
=
Image
.
open
(
path
)
if
idx
>=
1
:
# 第二张图之后裁剪
width
,
height
=
img
.
size
# 确保裁剪高度不超出原图范围
actual_crop
=
min
(
crop_height
,
height
)
print
(
'actual_crop'
,
actual_crop
)
# 左上
img
=
img
.
crop
((
0
,
actual_crop
,
width
,
height
))
images
.
append
(
img
)
# 计算总高度和最大宽度
total_height
=
sum
(
img
.
height
for
img
in
images
)
max_width
=
max
(
img
.
width
for
img
in
images
)
# 创建空白画布并拼接
merged
=
Image
.
new
(
'RGB'
,
(
max_width
,
total_height
))
y_offset
=
0
for
img
in
images
:
# 居中处理宽度不一致的图片
x_offset
=
(
max_width
-
img
.
width
)
//
2
merged
.
paste
(
img
,
(
x_offset
,
y_offset
))
y_offset
+=
img
.
height
merged
.
save
(
output_path
)
def
join_images
(
png1
,
png2
,
size
=
0
,
output
=
f
'
{
dir
}
/temp_result.png'
):
"""
图片拼接
:param png1: 图片1
:param png2: 图片2
:param size: 两个图片重叠的距离
:param output: 输出的图片文件
:return:
"""
size
=
size
*
2
img1
,
img2
=
Image
.
open
(
png1
),
Image
.
open
(
png2
)
size1
,
size2
=
img1
.
size
,
img2
.
size
joint
=
Image
.
new
(
'RGB'
,
(
size1
[
0
],
size1
[
1
]
+
size2
[
1
]
-
size
))
loc1
,
loc2
=
(
0
,
0
),
(
0
,
size1
[
1
]
-
size
)
joint
.
paste
(
img1
,
loc1
)
joint
.
paste
(
img2
,
loc2
)
joint
.
save
(
output
)
sleep
(.
5
)
def
run
():
global
driver
...
...
@@ -177,8 +242,7 @@ def mapMSg():
# return base64;
# })
# """)
cur_timestemp
=
int
(
round
(
time
.
time
()
*
1000
))
ScreenShot
.
screen_shot
(
driver
,
'outlook_'
+
str
(
cur_timestemp
))
screen_shot
(
driver
)
# print('base64Data',base64Data)
# email_box=driver.find_element(By.ID,':mt')
break
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录