如何获得Chrome搜索框的结果



我需要检索Chrome搜索框的搜索结果(ctrl+F(。我的python脚本需要与我的关键字匹配的数量。例如,"原纤维结构"的匹配结果在这里是"1/12",我需要复制这个"1/12">

这是我迄今为止的尝试:

from pywinauto.application import Application
from pywinauto.keyboard import SendKeys
app = Application()
app.start(r"C:Program Files (x86)GoogleChromeApplicationchrome.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"操作的网页实际上是一个网页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())

最新更新