2017-08-07 40 views
0

我已經創建了一個使用硒和一個webdriver(Chromedriver)的Python腳本。完成此腳本後,我使用cx_freeze將腳本編譯爲獨立的exe文件,然後雙擊執行該腳本。但是,對於硒,我一直在使用我下載的chromedriver文件,該文件可以在我已經安裝到我的電腦上的chrome應用程序中使用。啓動基於硒的獨立EXE沒有鉻安裝

我想做的或嘗試做的事情是讓我的exe文件與chromedriver一起工作,而不要求用戶將谷歌瀏覽器安裝到他們的計算機上。無論如何,我可以將chrome包含在同一個目錄中以解決此問題或其他問題?

我也接受其他想法。

回答

0

您可以隨時捆綁脫機安裝程序並提示它被安裝並運行可執行文件來安裝它。 (可用here

注意:可能有一些授權問題,您可能需要查看。

否則,請使用webbrowser.open('https://www.google.com/chrome/browser/')將它們引導至chrome的安裝頁面。例如:

try: 
    selenium.webbrowser('chrome') # Or whatever the command is 
except NameOfExceptionWhenNoBrowserHere: 
    # If you are opening the web page: 

    import webbrowser 

    INSTALL_PAGE = 'https://www.google.com/chrome/browser/' 
    print('You need to have Google chrome installed.') 
    print(INSTALL_PAGE) 
    if input('Open ' + INSTALL_PAGE + '? [yes/no]').lower().startswith('y'): 
     webbrowser.open(INSTALL_PAGE) # Uses default browser 

    # If you are running the offline installer 

    import subprocess 
    import os 

    _file_dir = os.path.dirname(os.path.realpath(__file__)) 

    print('You need to have Google chrome installed.') 
    print('Will now open installer') 

    # _file_dir is the directory of the python file. 
    # If the installer is in the same directory, run it like this. 
    subprocess.call(os.path.join(_file_dir, 'install_chrome.exe'))