javascript - How to split out consequent number? -
i movie time data website , find consequent .
how split out , become json data ? can not figure out.
any appreciated. in advance.
here json data made:
[{"title":["敦克爾克大行動 dunkirk","女狼嗨到趴 rough night","悟空傳 wukong","猩球崛起 終極決戰 war planet of apes","銀魂 gintama","蜘蛛人:返校日 spider-man: homecoming","神偷奶爸 3《中文版》 despicable me 3 《 ch 》 ","神偷奶爸 3《英文版》 despicable me 3《 en 》"],"time":["09:5011:5513:0014:0015:0016:0518:1019:2020:1522:2000:30\n","10:0011:5013:4015:3017:2020:5022:4000:30\n","10:0013:5516:1020:0522:2000:35\n","10:0012:3513:3515:1016:1017:4518:4520:2021:2022:5500:00\n","10:0017:0023:45\n","10:0012:2514:5017:1519:4021:2022:0500:30\n","10:0011:4519:10\n","12:1518:25\n"],"image":["picture/zip_20170617231635968.jpg","picture/zip_20170528225556605.jpg","picture/zip_20170528231038563.jpg","picture/zip_20170617225530468.jpg","picture/zip_20170617231105860.jpg","picture/zip_20170617224807245.jpg","picture/zip_20170617223724641.jpg","picture/zip_20170617223542725.jpg"]}]
i use casperjs movie time data:
var movietitle = []; var movietime = []; var movieimage = []; var allmovie = {}; allmovie.detail = []; // how let movie time split out ? function getmovietime() { var time = document.queryselectorall('ul li ul'); return array.prototype.map.call(time, function (e) { return e.innertext; }); } casper.then(function () { movietitle = this.evaluate(getmovietitle); movietime = this.evaluate(getmovietime); movieimage = this.evaluate(getmovieimage); }); casper.then(function () { console.log('what going on'); this.echo(movietitle.length + 'title found :'); // this.echo(movietitle.join('\n')); this.echo(movietime.length + 'time found :'); //this.echo(movietime.join('\n')); this.echo(movieimage.length + 'image found :') // this.echo(movieimage.join('\n')); this.echo(outputjson()); }); function outputjson() { allmovie.detail.push({ title: movietitle, time: movietime, image: movieimage }); return json.stringify(allmovie.detail); }
i have try this:
function getmovietime() { var time = document.queryselectorall('ul li ul'); return array.prototype.map.call(time, function (e) { return e.innertext.substring(0, 5); }); }
but each first movie time , not want.
used javascript functions split
, substring
, join
within loop desired result.
var data = [ { "title":[ "敦克爾克大行動 dunkirk", "女狼嗨到趴 rough night", "悟空傳 wukong", "猩球崛起 終極決戰 war planet of apes", "銀魂 gintama", "蜘蛛人:返校日 spider-man: homecoming", "神偷奶爸 3《中文版》 despicable me 3 《 ch 》 ", "神偷奶爸 3《英文版》 despicable me 3《 en 》" ], "time":[ "09:5011:5513:0014:0015:0016:0518:1019:2020:1522:2000:30\n", "10:0011:5013:4015:3017:2020:5022:4000:30\n", "10:0013:5516:1020:0522:2000:35\n", "10:0012:3513:3515:1016:1017:4518:4520:2021:2022:5500:00\n", "10:0017:0023:45\n", "10:0012:2514:5017:1519:4021:2022:0500:30\n", "10:0011:4519:10\n", "12:1518:25\n" ], "image":[ "picture/zip_20170617231635968.jpg", "picture/zip_20170528225556605.jpg", "picture/zip_20170528231038563.jpg", "picture/zip_20170617225530468.jpg", "picture/zip_20170617231105860.jpg", "picture/zip_20170617224807245.jpg", "picture/zip_20170617223724641.jpg", "picture/zip_20170617223542725.jpg" ] } ]; for(var i=0; i<data.length; i++){ var movie = data[i]; movie.time = getpropertime(movie.time); } console.log(movie.time[0]); function getpropertime(time){ for(var i=0;i<time.length; i++){ time[i] = time[i].split('\n')[0].split(":"); for(var j=1; j<time[i].length-1; j++){ time[i][j] = time[i][j].substring(0, 2) + "," + time[i][j].substring(2); } time[i] = time[i].join(":").split(","); } return time; }
Comments
Post a Comment