可以将locateOnScreen坐标传递给X Y参数以使用Python屏蔽某个区域吗?

时间:2017-12-09 20:52:02

标签: python coordinates screenshot region pyautogui

蟒蛇新手(过去几个月内),我很享受。它易于理解和使用。除了这种情况!

我写了一个脚本,用于登录使用selenium的网站,导航到特定页面,输入日期值并显示我需要的结果。它滚动到位,然后我需要截取该页面的一部分。起初我只是将它保存在整个屏幕上,我稍后会裁剪它,但我相信只有截取我需要的区域才有可能(而且效率更高)。

我已经尝试了多种方法来定位角落开始的位置并选择区域,最终决定使用locateCenterOnScreen与我想要的点的示例屏幕截图一起使用pyautogui,其中心标记左上角我要保存的整个部分。这确保了如果窗口每次都不在同一个地方,它将准确地保存正确的区域,无论它在哪里。

因此,使用

location = pyautogui.locateCenterOnScreen('ctr_cornerScreenshot.PNG')

返回正确的(X,Y)值以正确定位屏幕截图的坐标。然后,我正在使用

screengrabPic = pyautogui.screenshot(region=(location, 720, 340)) screengrabPic.save("transactions.png")

错误结果为

AssertionError: region argument must be a tuple of four ints

我确定因为location传入的区域参数,我已尝试(int(location)'locationX, locationY,

我想我会伸手去寻求帮助,而不是更多地转动我的车轮。谢谢!

1 个答案:

答案 0 :(得分:0)

好的,所以我做了更多的试验和错误,然后找到了最终的解决方案。

tail -20 /var/log/nginx/error.log


2017/12/10 05:06:30 [warn] 8810#0: conflicting server name "localhost" on 0.0.0.0:80, ignored
2017/12/10 05:06:30 [warn] 8818#0: conflicting server name "localhost" on 0.0.0.0:80, ignored
2017/12/10 05:08:31 [error] 8826#0: *2 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 190.104.119.69, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "138.197.195.201", referrer: "http://138.197.195.201/"
2017/12/10 05:29:51 [warn] 19171#0: conflicting server name "localhost" on 0.0.0.0:80, ignored
2017/12/10 05:29:51 [warn] 19176#0: conflicting server name "localhost" on 0.0.0.0:80, ignored
2017/12/10 05:43:49 [warn] 12191#0: conflicting server name "localhost" on 0.0.0.0:80, ignored
2017/12/10 05:43:50 [warn] 12203#0: conflicting server name "localhost" on 0.0.0.0:80, ignored
2017/12/10 06:01:29 [warn] 11819#0: conflicting server name "localhost" on 0.0.0.0:80, ignored
2017/12/10 06:01:30 [warn] 11825#0: conflicting server name "localhost" on 0.0.0.0:80, ignored
2017/12/10 06:01:48 [error] 11833#0: *1 directory index of "/var/www/mav/" is forbidden, client: 100.12.198.208, server: localhost, request: "GET / HTTP/1.1", host: "138.197.195.201"
2017/12/10 06:01:50 [error] 11833#0: *1 directory index of "/var/www/mav/" is forbidden, client: 100.12.198.208, server: localhost, request: "GET / HTTP/1.1", host: "138.197.195.201"
2017/12/10 06:01:52 [error] 11833#0: *1 directory index of "/var/www/mav/" is forbidden, client: 100.12.198.208, server: localhost, request: "GET / HTTP/1.1", host: "138.197.195.201"
 2017/12/10 06:04:57 [error] 11833#0: *4 directory index of "/var/www/mav/" is forbidden, client: 100.12.198.208, server: localhost, request: "GET / HTTP/1.1", host: "138.197.195.201"
2017/12/10 06:04:58 [error] 11833#0: *4 directory index of "/var/www/mav/" is forbidden, client: 100.12.198.208, server: localhost, request: "GET / HTTP/1.1", host: "138.197.195.201"
2017/12/10 06:04:59 [error] 11833#0: *4 directory index of "/var/www/mav/" is forbidden, client: 100.12.198.208, server: localhost, request: "GET / HTTP/1.1", host: "138.197.195.201"
2017/12/10 06:04:59 [error] 11833#0: *4 directory index of "/var/www/mav/" is forbidden, client: 100.12.198.208, server: localhost, request: "GET / HTTP/1.1", host: "138.197.195.201"
2017/12/10 06:11:38 [emerg] 30474#0: unknown directive "And" in /etc/nginx/nginx.conf:91
 2017/12/10 06:12:10 [emerg] 31474#0: unknown directive "And" in /etc/nginx/nginx.conf:91
2017/12/10 06:19:31 [emerg] 12641#0: unexpected end of file, expecting "}" in /etc/nginx/nginx.conf:89
2017/12/10 06:43:30 [emerg] 24459#0: unexpected end of file, expecting "}" in /etc/nginx/nginx.conf:89

在pyautogui.readthedocs上,它解释了这种语法,但并不是具体要求首先运行定位中心,然后再运行locationX和locationY。