我正在使用pyAutoGUI尝试在网站中查找图像。不过,我遇到了一个特定的错误,无法在线找到任何帮助。
这是我的代码:
#locate an image on screen
import pyautogui
from PIL import Image
screenWidth, screenHeight = pyautogui.size()
currentMouseX, currentMouseY = pyautogui.position()
#pause between actions in seconds
pyautogui.PAUSE = .5
#swap to firefox at first run so we can look for the image
pyautogui.hotkey('alt', 'tab')
# returns (left, top, width, height) of first place image is found (863, 417, 70, 13)
deleteButton = pyautogui.locateOnScreen('/home/user/path/to/filename.png')
print("location: ", str(deleteButton))
#come back to terminal to see if we worked or not
pyautogui.hotkey('alt', 'tab')
这是错误:
$ python3 locateImageOnCcreen.py
Traceback (most recent call last):
File "locateImageOnCcreen.py", line 17, in <module>
deleteButton = pyautogui.locateOnScreen('/home/user/path/to/filename.png')
File "/home/user/.local/lib/python3.6/site-packages/pyscreeze/__init__.py", line 271, in locateOnScreen
retVal = locate(image, screenshotIm, **kwargs)
File "/home/user/.local/lib/python3.6/site-packages/pyscreeze/__init__.py", line 255, in locate
points = tuple(locateAll(needleImage, haystackImage, **kwargs))
File "/home/user/.local/lib/python3.6/site-packages/pyscreeze/__init__.py", line 249, in _locateAll_python
raise ImageNotFoundException('Could not locate the image.')
pyscreeze.ImageNotFoundException: Could not locate the image.
当我从命令行复制并粘贴到文件资源管理器时,我可以保证图像的路径正确无误。
我在python 2和3中尝试过,出现相同的错误。
有人可以提供一些建议吗?
谢谢