Python能否与其他应用程序协作?

2024-06-16 10:58:19 发布

您现在位置:Python中文网/ 问答频道 /正文

Python能否与Chrome等应用程序合作?你知道吗

比如:

from Tkinter import *

from (straightAccesToApps) import (straightAccesToApps)

main = Tk()

def runChrome():
    straightAccesToApps('C:\\Desktop\Chrome').run()
    main.quit()

Button(main, text="Chrome", command=runChrome).pack()

main.mainloop()

Tags: runtextfromimport应用程序maintkinterdef
2条回答

通过selenium webdriver,事实上的行业标准:http://www.seleniumhq.org

是的,python可以通过多种方式做到这一点:

1.通过webbrowser等模块:

url = 'http://www.python.org/'

# Open URL in a new tab, if a browser window is already open.
webbrowser.open_new_tab(url + 'doc/')

# Open URL in new window, raising the window if possible.
webbrowser.open_new(url)

2.通过os.systemsubprocess.call

import os
os.system("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe -ArgumentList @( '-incognito', 'www.site.com'" )

3.通过powershell,但这有点过分了

import subprocess
subprocess.call(["C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\powershell.exe", ". \"./SamplePowershell\";", 'Start-Process "chrome.exe" "www.google.com"'])

相关问题 更多 >