繁体   English   中英

如何使用 Python 3

[英]How to download and silent install .exe file with given URL using Python 3

我有一个 URL,它是一个 software.exe 文件的下载链接。 预期的操作是使用 Python 3 下载上述文件,然后进行静默安装。

import ssl
from urllib.parse import urlparse
import requests

#convert to string
url = str(url) 

#convert ftp download path to http and remove chars to make it downloadable 
httpurl = re.sub("ftp://","https://",url)
print("url is: " + url)


#function to break file name from the full path
def split(downloadurl):
    p,downloadexename = os.path.split(downloadurl)
    return [downloadexename]

#Remove all the unnecessary stuff you don't need
downloadurl = httpurl.replace("'","").replace(',','').replace(":2100/FTP Folders/Software","").replace(" ","%20").strip("(").strip(")")
print("Download URL is: "+downloadurl)

down_name = os.path.basename(downloadurl)
down_dir = r"C:\Desktop"
                 
#Create folder if it doesn't exist for download as required 
if not os.path.exists(down_dir):
    os.makedirs(down_dir)
full_path = os.path.join(down_dir, down_name)

# Silent Install
subprocess.call([full_path, '/Silent'], shell=True)

这取决于.exe是哪种安装程序,但它很有可能已经具备静默安装的能力。 例如,InnoSetup 安装程序(一种非常常见的类型)使用参数/SILENT 如果您不知道安装程序的类型,您可以尝试使用/s/S/SILENT等的不同变体运行.exe - 或/?的某些变体。 , --help显示命令行用法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM