python 模块'functions'没有属性' functions'

kuuvgm7e  于 5个月前  发布在  Python
关注(0)|答案(3)|浏览(68)

我正在编写一个机器人与浏览器交互(不要说服我重写Selenium或键盘和其他),它给了我一个错误。附近没有名为pyautogui的文件,我试着将其命名为main和python v3.8,3.9。在每种情况下都收到此错误。MacOS

/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/rubicon/objc/ctypes_patch.py:21: UserWarning: rubicon.objc.ctypes_patch has only been tested with Python 3.4 through 3.8. You are using Python 3.9.4. Most likely things will work properly, but you may experience crashes if Python's internals have changed significantly.
  warnings.warn(
Traceback (most recent call last):
  File "/Users/alina/PycharmProjects/ABOBA/main_miner_alienworlds.py", line 183, in <module>
    for i in pyautogui.getWindowsWithTitle('##### #######'):
AttributeError: module 'pyautogui' has no attribute 'getWindowsWithTitle'

个字符
pyautogui是用pip3安装的

jum4pzuy

jum4pzuy1#

你用错模块了!
https://pypi.org/project/PyGetWindow/是包含getWindowsWithTitle的模块

7vhp5slm

7vhp5slm2#

不幸的是,从0.9.53版本开始,pyautogui的windows功能只能在Windows上工作,请参阅下面的https://i.stack.imgur.com/HKtcC.png源代码:-https://automatetheboringstuff.com/2e/chapter20/

vyswwuz2

vyswwuz23#

对于macOS用户,您可能需要使用Quartz和AppKit。
一般来说,AppKit是内置的,因此您只需通过以下方式安装Quartz:

pip install pyobjc

字符串
获取窗口信息:

import Quartz
from AppKit import NSWorkspace

# This function retrieves a list of all windows with their titles
def get_window_list():
    window_list = []
    window_info_list = Quartz.CGWindowListCopyWindowInfo(Quartz.kCGWindowListOptionOnScreenOnly, Quartz.kCGNullWindowID)
    for window_info in window_info_list:
        window_list.append(window_info)
    return window_list

# This function will look for a window with a specific title
def get_window_with_title(title):
    for window in get_window_list():
        window_title = window.get('kCGWindowName', 'No Title')
        if window_title == title:
            return window
    return None

# Replace 'Your Window Title' with the actual title of the window you're looking for
window_title = "xxx"
window = get_window_with_title(window_title)
print(window)


你会看到这样的结果:

{
    kCGWindowAlpha = 1;
    kCGWindowBounds =     {
        Height = 851;
        Width = 515;
        X = 0;
        Y = 37;
    };
    kCGWindowIsOnscreen = 1;
    kCGWindowLayer = 0;
    kCGWindowMemoryUsage = 2160;
    kCGWindowName = xxx;
    kCGWindowNumber = 24901;
    kCGWindowOwnerName = Aethric;
    kCGWindowOwnerPID = 41114;
    kCGWindowSharingState = 1;
    kCGWindowStoreType = 1;
}

相关问题