以编程方式打开浏览器选项卡的列表 [英] List of open browser tabs programmatically

查看:59
本文介绍了以编程方式打开浏览器选项卡的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过编程方式以索引方式获取浏览器中的打开的标签页列表

Is there a way to programmatically obtain a list of open tabs in a browser by index?

例如,假设Google Chrome浏览器是

在程序中,一行类似于:

For example, suppose Google Chrome is open with two tabs.
In the program, a line something like:

tabs_list = list_tabs(hwnd)

...其中hwnd是整个Chrome实例窗口的句柄,而tabs_list是字典,例如:

...where hwnd is the handle to the window for the overall Chrome instance and tabs_list is a dictionary something like:

[
0 : 'http://stackoverflow.com/',
1 : 'http://www.coolstuffff.com/'
]

(。 ..或按窗口标题代替url)

(...or maybe by title of the window instead of url)

如果是这样,则可以使用键盘的Python脚本将焦点集中到其中之一

添加了修改稍后尝试帮助澄清:给本地wxPython应用程序添加图片,您已经在其中知道如何在该sa上激活给定的Chrome实例。从本地运行的wxPython应用程序中找到我框,并且该浏览器实例打开了多个标签,现在您要确保某个标签具有焦点,以便能够与正在显示的网页进行交互(也许使用CTRL-例如CTRL-C来收获其内容)。这个问题与发出键盘命令无关,众所周知,这个问题是如何获取打开的选项卡列表,如果可能的话,谢谢。

An edit added later to try to help clarify: Picture a local wxPython app, where you already know how to activate a given instance of Chrome on that same box from within your wxPython app running locally, and that browser instance has multiple tabs open, and now you want to insure that a certain tab has focus, to be able to interact with that web page that is being displayed (maybe using CTRL-A CTRL-C for example to harvest its content). This question is not about issuing keyboard commands, that is already known, the question is how to obtain a list of open tabs, if possible, thanks.

推荐答案

虽然不确定目标操作系统,但可以在Mac OS X上执行此操作:

While not sure of your target OS, you can do this on Mac OS X:

>>> from appscript import *
>>> map(lambda x: x.title(), app('Google Chrome').windows[0].tabs())
[u'Stack Overflow', u'Google']

在Windows上,您将要研究使用Python的OLE Automation。

On Windows, you will want to look into OLE Automation with Python.

这篇关于以编程方式打开浏览器选项卡的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆