2017-08-08 90 views
2

Python可以與Chrome這樣的應用程序合作嗎?Python可以與其他應用程序合作嗎?

喜歡的東西:

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() 
+4

是Python可以做到這一點 – Veltro

+0

對於額外工作進程,子進程是很好的方法 - https://pymotw.com/2/subprocess/ – anatol

回答

3

是Python可以做到這一點在許多方面:

1.Via模塊,如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.Via os.systemsubprocess.call

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

3.Via PowerShell的,但就是有點矯枉過正一個

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

你可以使用'string = shlex.split(string)'來獲得subprocess.call()所期望的字符串。 –

+0

謝謝,我明白了,爲什麼你總是刪除你的評論?這就像你第四次寫這個。 @lecaruyer – Veltro

0

的通過硒webdriver的,事實上的行業標準:http://www.seleniumhq.org

+0

我認爲這個答案太具體了,他不僅想要打開瀏覽器,問題是關於python與其他應用程序合作,而不僅僅是web瀏覽器 – Veltro

相關問題