• elemnetui 下载,及引用


    一、下载

    # encoding:utf-8
    from bs4 import BeautifulSoup
    import requests, re, os, socket
    from urllib import request
    #指定要下载的版本
    element_ui_version = "2.13.0"
    # 指定文件要存放的位置
    element_ui_dir = "D:download"
    
    
    save_ui_dir = os.path.join(element_ui_dir,"element-ui")
    
    if not os.path.isdir(save_ui_dir):
        os.makedirs(save_ui_dir)
    
    element_ui_url = "https://unpkg.com/browse/element-ui@" + element_ui_version + "/"
    headers = {
        "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:73.0) Gecko/20100101 Firefox/73.0"
    }
    
    def get_page(url,save_dir):
        print("Current Page:",url)
        response = requests.get(url,headers=headers)
        soup = BeautifulSoup(str(response.content), "lxml")
        tbody = soup.find("tbody")
        rule_name = r'href="(.+?)"'
        td_href = re.findall(rule_name,str(tbody))
        dir_list = []
        for href in td_href:
            href_path = os.path.join(save_dir, href)
            if href == "../":
                pass
            elif "/" in href:
    
                os.mkdir(href_path)
                print("Makedir:    ",href_path.replace(save_ui_dir,""))
                dir_list.append(href)
            else:
                file_url = url + href
                abs_name = file_url.replace(element_ui_url, "")
                print("Download:    ", abs_name)
                get_file(file_url,href_path)
    
    
        for sub_dir in dir_list:
            sub_url = url + sub_dir
            sub_dir = os.path.join(save_dir,sub_dir)
            get_page(sub_url,sub_dir)
    
    def get_file(url,filename):
        opener =request.build_opener()
        opener.addheaders = [('User-agent',
                              'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:73.0) Gecko/20100101 Firefox/73.0')]
        request.install_opener(opener)
        socket.setdefaulttimeout(30)
        url = url.replace("browse/","")
        count = 1
        while count <= 5:
            try:
                request.urlretrieve(url, filename)
                break
            except socket.timeout:
                err_info = '<Timeout>   Reloading for %d time' % count
                print(err_info)
                count += 1
            except Exception as e:
                err_info = '<'+str(e)+'>   Reloading for %d time' % count
                print(err_info)
                count += 1
        if count > 5:
            print("<Error>  download job failed!")
        else:
            pass
    
    
    get_page(element_ui_url,save_ui_dir)

    二、引用

    <link rel="stylesheet" href="/static/element-ui/lib/theme-chalk/index.css">
    {#<script src="//unpkg.com/vue/dist/vue.js"></script>#}
    <script src="/static/vue.js"></script>
    <script src="/static/element-ui/lib/index.js"></script>
    {#<script src="//unpkg.com/element-ui@2.13.1/lib/index.js"></script>d#}
    <script src="/static/index.js"></script>
  • 相关阅读:
    pthread_once函数的简单示例
    pthread_join直接决定资源是否能够及时释放
    非分离线程未使用join函数例子:
    一个HTTP打趴80%面试者
    BM和KMP字符串匹配算法学习
    STL 几个容器的底层实现
    指针的引用(*&)与指针的指针(**)
    Maven 环境变量设置
    配置JAVA的环境变量
    Maven报错 解决方案。ERROR: No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id
  • 原文地址:https://www.cnblogs.com/wt7018/p/12979381.html
Copyright © 2020-2023  润新知