Skip to content

Tips: Mac上使用该工具,框坐标需要乘以2 #12

@SWHL

Description

@SWHL

在用MacBook用该工具时,发现最终裁剪的表格总是原始表格部分内容,不完整。

参考python使用selenium截屏后再截取指定坐标图片定位不准确是为什么 回答,解决了问题。

更改以下位置代码

max_height, max_width = window_size['height'], window_size['width']
# element = WebDriverWait(self.driver, 3).until(EC.presence_of_element_located((By.ID, '0')))
contens = []
for id in range(id_count):
# e = driver.find_element_by_id(str(id))
e = WebDriverWait(
self.driver,
3).until(EC.presence_of_element_located((By.ID, str(id))))
txt = e.text.strip()
lentext = len(txt)
loc = e.location
size_ = e.size
xmin = loc['x']
ymin = loc['y']
xmax = int(size_['width'] + xmin)
ymax = int(size_['height'] + ymin)
contens.append([
lentext, txt, [[xmin, ymin], [xmax, ymin], [xmax, ymax],
[xmin, ymax]]
])

为以下:

ratio = 2
max_height, max_width = window_size["height"], window_size["width"]
max_height *= ratio
max_width *= ratio
contens = []
for idx in range(id_count):
    e = WebDriverWait(self.driver, 3).until(
        EC.presence_of_element_located((By.ID, str(idx)))
    )
    txt = e.text.strip()
    lentext = len(txt)
    loc = e.location
    size_ = e.size
    xmin = loc["x"]
    ymin = loc["y"]
    xmax = int(size_["width"] + xmin)
    ymax = int(size_["height"] + ymin)

    xmin *= ratio
    ymin *= ratio
    xmax *= ratio
    ymax *= ratio
    contens.append(
        [lentext, txt, [[xmin, ymin], [xmax, ymin], [xmax, ymax], [xmin, ymax]]]
    )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions