Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
SWHL opened this issue Dec 27, 2023 · 2 comments
Open

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

SWHL opened this issue Dec 27, 2023 · 2 comments

Comments

@SWHL
Copy link
Contributor

SWHL commented Dec 27, 2023

在用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]]]
    )
@WenmuZhou
Copy link
Owner

欢迎提个pr

@SWHL
Copy link
Contributor Author

SWHL commented Jan 3, 2024

没问题,我整理一下。

之前也一直想写这个工具来着,后来发现您先做了。巧了不是。

@SWHL SWHL mentioned this issue Jan 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants