如何获取Chrome搜索框的结果?

How to get the result of the Chrome search box?

我需要检索 Chrome 搜索框 (ctrl + F) 的搜索结果。我的 python 脚本需要与我的关键字匹配的数量。比如这里'fibril structure'的匹配结果是'1/12',我需要复制这个'1/12'ctrl+f search result for 'fibril structure'

这是我目前的尝试:

from pywinauto.application import Application
from pywinauto.keyboard import SendKeys

app = Application()
app.start(r"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe")

app=Application().connect(title='New Tab - Google Chrome')    
window=app.Chrome_WidgetWin_1

window.TypeKeys('^F')
window.TypeKeys('hello world')

window.print_control_identifiers()

我已经尝试过 Pywinauto,但无法找到此对话框。此外,我运行 'ctrl+F' 操作所在的网页实际上是一个Web PDF (https://sci-hub.do/10.1038/s41594-020-0496-3),因此我无法使用Selenium 中的xpath 方法定位我的元素。

有人可以给我一些提示,告诉我如何完成这项工作吗?

您必须在代码后添加此代码:

desktop = pywinauto.Desktop(backend='uia', allow_magic_lookup=False)
window = desktop.windows(title='New Tab - Google Chrome', control_type='Pane')[0]
result = window.descendants(control_type='StatusBar')[0]
print(result.texts())