
python
import os
import urllib.request
import re
def download_chrome(url, save_path):
response = urllib.request.urlopen(url)
content = response.read()
提取文件名
file_name = re.search('^/([^/]*)$', url).group(1)
创建保存路径
dir_name = os.path.dirname(save_path)
if not os.path.exists(dir_name):
os.makedirs(dir_name)
写入文件
with open(save_path, 'wb') as f:
f.write(content)
print(f"Downloaded {file_name} to {save_path}")
if __name__ == '__main__':
url = 'https://dl.google.com/linux/direct/google-chrome-stable/current/google-chrome-stable-current.tar.gz'
save_path = '/tmp/chrome.tar.gz'
download_chrome(url, save_path)
这个脚本会从指定的 URL 下载 Google Chrome 的 tarball 文件,并将其保存到当前目录下的 `chrome.tar.gz` 文件中。请确保在运行此脚本之前已经安装了 Python。



