制作便携式Chrome浏览器

1.为什么需要便携式谷歌浏览器?

我们尝试问下ai
在这里插入图片描述

但对于浏览器自动化而言,好处还是很明显的:

  1. 固定浏览器版本,不用担心浏览器自动生成导致驱动不匹配
  2. 某些场景只能固定某些版本使用,例如Chrome 72禁用对TLS 1.0和TLS 1.1的支持,而ccb网银就需要老版本的tls,换成72版本之前即可
  3. 程序分发时可以直接打包chrome进去,而无需担心用户电脑环境是否安装了目标版本的浏览器

2.如何制作便携式谷歌浏览器

2.1 提取启动器GoogleChromePortable.exe

访问google_chrome_portable下载

下载得到GoogleChromePortable_125.0.6422.142_online.paf.exe,版本号可能不一致

解压得到GoogleChromePortable.exe

2.2 下载官方离线包

  • https://chrome.wums.cn/
  • https://www.chromedownloads.net/chrome64win-stable/

可按需下载

2.3 制作离线包

步骤:

  • 将chrome离线包107.0.5304.122_chrome64_stable_windows_installer.exe更改名称为107.0.5304.122_chrome64_stable_windows_installer.zip(版本号根据实际情况来)
  • 解压该zip
  • 在解压完的文件中找到chrome.7z,解压chrome.7z
  • 创建App目录,将解压完的Chrome-bin目录放到其中
  • 创建data目录,存放浏览器配置信息
  • 将GoogleChromePortable.exe放到同级目录,改名chrome.exe
  • 便携式谷歌浏览器制作完毕,通过chrome.exe启动即可

最终结构如下:

2.4 禁用谷歌浏览器升级提示

启动时添加--disable-background-networking 启动参数即可

3.使用python来自动化生成

备注:使用了Bandizip.exe来自动化解压,需要安装Bandizip并将Bandizip.exe添加到环境变量

import logging as log  
import shutil  
import subprocess  
from pathlib import Path  
  
log.basicConfig(level=log.INFO, format='%(asctime)s - %(levelname)s - %(message)s')  
  
  
class LocalChrome():  
    def __init__(self,chrome_path):  
        # 备份chrome,将exe改名为zip  
        self.chrome_path = chrome_path  
        self.chrome_dir = Path(self.chrome_path).parent  
        self.chrome_zip = Path(self.chrome_dir).joinpath(Path(self.chrome_path).name.replace(".exe",".zip"))  
    
    def backup(self):  
        # 备份chrome,将exe改名为zip  
        if Path(self.chrome_path).exists():  
            if self.chrome_zip.exists():  
                return  
            shutil.copy(self.chrome_path,self.chrome_zip)  
        else:  
            log.error("chrome not exists")  
  
    def unzip(self):  
        # 解压zip  
        if self.chrome_zip.exists():  
            # 编写解压代码  
            unzip_dir = self.chrome_zip.parent.joinpath(self.chrome_zip.name.replace(".zip",""))  
            if unzip_dir.exists():  
                shutil.rmtree(unzip_dir)  
            unzip_dir.mkdir()  
            self.unzip_file(self.chrome_zip,unzip_dir)  
        else:  
            log.error("chrome zip not exists")  
  
    @staticmethod  
    def unzip_file(zip_file_path, extract_dir):  
        extract_dir = Path(extract_dir)  
        if extract_dir.exists():  
            shutil.rmtree(extract_dir)  
        extract_dir_str = str(extract_dir.resolve())  
        if not extract_dir_str.endswith("\\"):  
            extract_dir_str += "\\"  
        res = subprocess.check_output(['Bandizip.exe','x','-y','-o:%s' % extract_dir_str, zip_file_path])  
        log.info(res)  
  
  
if __name__=="__main__":  
    # GoogleChromePortable路径
    chrome_portable = r"D:\chrome\GoogleChromePortable.exe"  
    # 离线包路径
    chrome_path = r"D:\chrome\107.0.5304.122_chrome64_stable_windows_installer.exe"  
    zip_file_path = chrome_path.replace(".exe",".zip")  
    extract_dir = zip_file_path.replace(".zip","")  
    chrome = LocalChrome(chrome_path =chrome_path)  
    chrome.backup()  
    # 解压zip文件  
    chrome.unzip_file(zip_file_path,extract_dir)  
    # 解压7z文件  
    chrome7z = Path(extract_dir).joinpath("chrome.7z")  
    chrome7z_path = str(chrome7z.resolve())  
    chrome7z_exact_path = chrome7z_path.replace(".7z", "")  
    chrome7z_exact_path_str = str(Path(chrome7z_exact_path).resolve())  
    chrome.unzip_file(chrome7z_path,chrome7z_exact_path_str)  
    # 创建目标目录  
    zip_file = Path(zip_file_path)  
    zip_file_name = zip_file.name  
    # 获取版本号  
    version = zip_file_name.split("_chrome")[0]  
    target_dir = zip_file.parent.joinpath("chrome_%s" % version)  
    if target_dir.exists():  
        shutil.rmtree(target_dir)  
    # 创建App目录 data目录  
    app_dir = target_dir.joinpath("App")  
    app_dir.mkdir(parents=True,exist_ok=True)  
    data_dir = target_dir.joinpath("data")  
    data_dir.mkdir(parents=True,exist_ok=True)  
    # 复制文件  
    shutil.copytree(chrome7z_exact_path_str+"\\Chrome-bin",str(app_dir.joinpath("Chrome-bin").resolve()))  
    shutil.copy(chrome_portable,str(target_dir.joinpath("chrome.exe").resolve()))  
    # 删除文件  
    Path(zip_file_path).unlink()  
    shutil.rmtree(extract_dir)
  • 10
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
便携式Ubuntu制作是指将Ubuntu操作系统安装到一个可移动的存储设备(如USB闪存驱动器)上,以便在不同的计算机上使用。这样可以方便地携带自己的操作系统和个人设置,而无需每次都重新安装和配置。 以下是制作便携式Ubuntu的步骤: 1. 下载Ubuntu ISO镜像:首先,你需要从Ubuntu官方网站下载适合你的计算机架构的Ubuntu ISO镜像文件。你可以选择最新版本或者其他特定版本。 2. 创建启动盘:接下来,你需要将Ubuntu ISO镜像写入一个可启动的USB闪存驱动器。你可以使用一些工具如Rufus、Etcher或UNetbootin来完成这个步骤。这些工具会将ISO镜像写入USB驱动器,并使其成为可启动的Ubuntu安装介质。 3. 安装Ubuntu:将制作好的启动盘插入目标计算机,并重启计算机。在启动过程中,按下相应的按键(通常是F12、F2或Delete键)进入计算机的启动菜单。选择从USB驱动器启动,并按照屏幕上的指示进行Ubuntu的安装过程。 4. 配置个人设置:在安装完成后,你可以根据自己的需求进行个人设置,如语言、时区、网络连接等。你还可以安装所需的软件和配置系统环境。 5. 携带和使用:完成上述步骤后,你就可以将USB闪存驱动器作为便携式Ubuntu使用了。只需将该驱动器插入任何计算机的USB接口,并在启动时选择从USB启动,即可使用你的个人Ubuntu系统。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值