• 最佳同步方法 prom + await


    for(let i = 0;i<256;i++){
        const sres = await getIndex(i);
    }
    
    
    function createMovie1(parr){
        let movie1 = {};
        parr.forEach(v=>{  
            if(v.substr(0,"译  名".length)=="译  名"){
                movie1.yiname = v;
            }
            if(v.substr(0,"片  名".length)=="片  名"){
                movie1.name = v;
            }
            if(v.substr(0,"年  代".length)=="年  代"){
                movie1.year = v;
            }
            if(v.substr(0,"产  地".length)=="产  地"){
                movie1.where = v;
            }
            if(v.substr(0,"产  地".length)=="产  地"){
                movie1.where = v;
            }
            if(v.substr(0,"导  演".length)=="导  演"){
                movie1.direct = v;
            }
            if(v.substr(0,"主  演".length)=="主  演"){
                movie1.actor = v;
            }
            if(v.substr(0,"简  介".length)=="简  介"){
                movie1.jianjie = v;
            }
           
        });
        return movie1;
    }
    
    const  url2 = 'http://localhost/f2.html';
    async function getMovieFromUrl(url){
    
        console.log(url)
        const sres = await superagent.get(url).charset('gbk');
    
        let html = sres.text,
            $ = cheerio.load(html, {
                decodeEntities: false
            }), //用cheerio解析页面数据
            obj = {};
        let text='';
        $("p").each((index, element) => {
            let $text = $(element).text();
            text=text+$text;
        });
    
        $("p img").each((index, element) => {
            let $imgurl = $(element).attr("src");
            console.log($imgurl)
        });
        let parr = text.split('◎')
        let movie1 = createMovie1(parr);
        console.log(movie1);      
    }
    
    getMovieFromUrl(url2)
  • 相关阅读:
    java 单例设计模式
    JAVAWEB监听器(二)
    pxe无人值守安装linux机器笔记----摘抄
    Ganglia3.1.7安装与配置(收录)
    Hadoop Sentry 学习
    安装和配置Sentry(收录)
    sqoop 的使用 -20160410
    深度分析如何在Hadoop中控制Map的数量(摘抄)
    CDH,CM下载
    大数据培训班 cloudera公司讲师面对面授课 CCDH CCAH CCP
  • 原文地址:https://www.cnblogs.com/cnchengv/p/10821380.html
Copyright © 2020-2023  润新知