如何准确地从pywin32中当前打开的浏览器选项卡中获取URL?

时间:2018-10-30 07:23:44

标签: python pywin32

我想知道如何从当前打开的浏览器选项卡获取url,我已经在浏览器上创建了处理程序,但是如何从他获取数据?

from win32com.client import Dispatch, GetObject
import win32gui, win32process

def main():
    while True:
        pid = win32process.GetWindowThreadProcessId(win32gui.GetForegroundWindow())
        process_id = int(pid[-1])
        _wmi = GetObject('winmgmts:')
        processes = _wmi.ExecQuery('Select * from win32_process')
        for p in processes:
            if isinstance(p.ProcessId, int) and p.ProcessId == process_id:
                p_name = p.Name.lower().replace('.exe', '')
                if p_name == 'firefox' or p_name == 'Firefox' or p_name == 'chrome' or p_name == 'google chrome':
                    #get_info
                else:
                    continue
if __name__ == '__main__':
    #getting_all_browser_names = get_open_browsers(SHELL)
    main()

0 个答案:

没有答案