如何滚动查看网站上的图像?

2024-09-30 14:15:25 发布

您现在位置: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

它一直向下滚动,即使屏幕上有图像也不会停止,因为图像是正确的


Tags: 图像程序nonefalseif屏幕pngis
1条回答
网友
1楼 · 发布于 2024-09-30 14:15:25

我认为你需要为你想找到的每一件东西设置一个标志。按照现在编写代码的方式,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的版本,您可能需要更新代码才能使用try…except块。从docs开始:

NOTE: As of version 0.9.41, if the locate functions can’t find the provided image, they’ll raise ImageNotFoundException instead of returning None.

相关问题 更多 >

    热门问题