美文网首页
selenium webdriver chrome 浏览器驱动下

selenium webdriver chrome 浏览器驱动下

作者: 秋一哲 | 来源:发表于2020-10-04 11:56 被阅读0次

    驱动地址

    http://chromedriver.storage.googleapis.com/index.html

    浏览器历史版本

    https://mydown.yesky.com/pcsoft/105582038/versions/

    python代码下载并且解压

    from urllib import request
    import zipfile
    def fun(blocknum,blocksize,totalsize):
        """
        blocknum:当前的块编号
        blocksize:每次传输的块大小
        totalsize:网页文件总大小
        """
        percent = blocknum*blocksize/totalsize
        if percent > 1.0:
            percent = 1.0
        percent = percent*100
        print("download : %.2f%%" %(percent))
    
    def chromedriver_download(pid,path):
        '''
        pid:驱动版本 浏览器和对应驱动可以在下面查看
        http://chromedriver.storage.googleapis.com/index.html
        https://mydown.yesky.com/pcsoft/105582038/versions/
        path:保存的文件夹路径
        '''
        # pid = '85.0.4183.38'
        # path = "LoginScript/data/"+pid+"/"
        path=path + pid+"/"
        if not os.path.exists(path):
            os.makedirs(path)
        filePath =  path+"chromedriver_win32.zip"
        opener = request.build_opener()
        opener.addheaders = ([
            ("User-Agent","Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36"),
            ])
        request.install_opener(opener)
        request.urlretrieve("http://chromedriver.storage.googleapis.com/"+pid+"/chromedriver_win32.zip",filePath,fun)
        f = zipfile.ZipFile(filePath,'r')
        for file in f.namelist():
            f.extract(file,path)
        f.close()
        os.remove(filePath)
    chromedriver_download("84.0.4147.30","D:/APP/")
    

    有的时候下载速度特别慢,也可能卡顿不知道为啥

    相关文章

      网友评论

          本文标题:selenium webdriver chrome 浏览器驱动下

          本文链接:https://www.haomeiwen.com/subject/aauwuktx.html