python - 如何滚动查看网站上的图像?
问题描述
所以我有这个程序,它旨在向下滚动,直到它可以找到屏幕上的所有图片。这是我的代码:
def scrolluntil():
allsat = False
while allsat == False:
pyautogui.scroll(-100)
fan = locateCenterOnScreen("findaname.png")
tl = locateCenterOnScreen("topleft.png")
tr = locateCenterOnScreen("topright.png")
if fan is not None:
if tl is not None:
if tr is not None:
allsat = True
它一直向下滚动并且即使图像在屏幕上也不会停止,图片是正确的。
解决方案
我认为您需要为要查找的每个内容设置一个标志。现在编写代码的方式,allsat=True
只有在所有图片同时在视图中时才会执行。
这是一种粗略的方法:
def scrolluntil():
allsat = False
fan = False
tl = False
tr = False
while allsat == False:
pyautogui.scroll(-100)
if fan == False:
if locateCenterOnScreen("findaname.png") is not None:
fan = True
if tl == False:
if locateCenterOnScreen("topleft.png") is not None:
tl = True
if tr == False:
if locateCenterOnScreen("topright.png") is not None:
tr = True
if fan:
if tl:
if tr:
allsat = True
还值得注意的是,如果您升级了pyautogui
. 从文档:
注意:从 0.9.41 版开始,如果定位函数找不到提供的图像,它们将引发 ImageNotFoundException 而不是返回 None。
推荐阅读
- reactjs - 为什么关键帧动画在 React 应用程序中渲染滞后?
- javascript - React:单击时如何防止按钮(从 react-scroll 导入)滚动
- python - 如何在 Python 中使用谓词
- node.js - 将图像上传到 azure blob 存储后如何返回图像的 url?
- discord.js - 如何从 API 中提取数据并将其嵌入
- php - PHP - 将 x-www-form-urlencoded 重复键读入数组
- javascript - 在没有 ActiveX 的 Vue.js 应用程序中安排 Outlook 会议
- r - 我可以在 r 中复制它吗(通过 Excel 方法)
- java - 杰克逊自定义序列化器与空值被抑制
- dymola - 如何在 Dymola 2021 中使用英特尔 MKL 库