为什么正则表达式在Pywinauto中不能很好地工作

时间:2016-02-19 02:22:47

标签: python regex google-chrome pywinauto

from pywinauto import application

app=application.Application()
3. app.connect(title_re = "/Zero Hedge$/")
4. app.connect(title_re = "/| Zero Hedge/")

我想像这样得到一个Chrome窗口:http://www.zerohedge.com/news/2016-02-18/markets-ignore-fundamentals-and-chase-headlines-because-they-are-dying

正如您在访问网站时所看到的,网站标题包含" | Zero Hedge"在它的最后部分或只是" Zero Hedge"遏制。

但是,无论是第3行还是第4行,我仍然会引发一个WindowNotFoundError。为什么正则表达式不起作用?

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

尝试此操作以获取所有窗口/标题的列表:

from pywinauto import findwindows

print findwindows.find_windows(title_re=".*")

这应该会为您提供所有窗口的列表,然后根据结果构建您的正则表达式。