Created
November 1, 2015 09:16
-
-
Save matsurai25/0a3cee90cb82c21f2be5 to your computer and use it in GitHub Desktop.
M3_json_getter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // m3のサイトからjsonデータを出力 | |
| var json = []; | |
| var no_tw = { | |
| count:0, | |
| circles:[], | |
| } | |
| $("tr").each(function(i,x){ | |
| // if(i > 30){ | |
| // return | |
| // } | |
| var tmp = {}; | |
| tmp.booth = $(" .left",x).text().replace(/\t| /g,""); | |
| tmp.circle_name = $(" .center a:first",x).text().replace(/\t| /g,""); | |
| if(!tmp.circle_name){ | |
| tmp.circle_name = $(" .center li:first",x).text().replace(/\t| /g,""); | |
| } | |
| if(!tmp.circle_name){ | |
| tmp.circle_name = $(" .center",x).text().replace(/\t| /g,""); | |
| } | |
| tmp.link = $(" .center a:first",x).attr("href"); | |
| var twitter = $(" .center a[href*=twitter]:first",x).attr("href"); | |
| if(twitter){ | |
| var tw_array = twitter.split("/"); | |
| if(tw_array[tw_array.length-1] == ""){ | |
| tmp.twitter_id = tw_array[tw_array.length-2]; | |
| console.log("最後が/"); | |
| console.log(tmp.twitter_id); | |
| }else{ | |
| tmp.twitter_id = tw_array[tw_array.length-1]; | |
| } | |
| }else{ | |
| tmp.twitter_id = ""; | |
| no_tw.count++; | |
| no_tw.circles.push(tmp); | |
| } | |
| if(tmp.twitter_id.match(/^[0-9a-z_]{1,15}$/i) == null || tmp.twitter_id == "share" || tmp.twitter_id == 1){ | |
| tmp.twitter_id = ""; | |
| } | |
| tmp.twitter_id = tmp.twitter_id.split("?")[0].replace( /@/g , "" ); | |
| tmp.explanation = $(" .right",x).text().replace(/\t| /g,""); | |
| if(!tmp.explanation){ | |
| tmp.explanation = $(" td:last-child",x).text().replace(/\t| /g,""); | |
| } | |
| // ジャンルコードを取得 | |
| var $elm = $(" .center",x); | |
| var $comment = $elm.contents().filter(function() { | |
| return this.nodeType === document.COMMENT_NODE; | |
| }); | |
| $comment.each(function(i, elm) { | |
| tmp.genrecode = elm.data.replace(/\t| /g,",").split(","); | |
| tmp.genrecode.splice(0, 3); | |
| tmp.genrecode.splice(-1, 1); | |
| for (var i = tmp.genrecode.length - 1; i >= 0; i--) { | |
| if(i%2 == 1){ | |
| tmp.genrecode.splice(i, 1); | |
| } | |
| }; | |
| for (var i = tmp.genrecode.length - 1; i >= 0; i--) { | |
| if(tmp.genrecode[i] == ""){ | |
| tmp.genrecode.splice(i, 1); | |
| } | |
| }; | |
| tmp.genrecode = ArrayToCSV(tmp.genrecode); | |
| // console.log(tmp.genrecode); | |
| }); | |
| json.push(tmp) | |
| }) | |
| function ArrayToCSV(array){ | |
| var csv=""; | |
| for(var i=0;i<array.length;i++){ | |
| csv+=array[i]+","; | |
| } | |
| csv=csv.slice(0,-1); | |
| return csv; | |
| } | |
| // $(no_tw.circles).each(function(i,x){ | |
| // console.log(x.circle_name); | |
| // console.log(x.link); | |
| // $.ajax({ | |
| // url: x.link, | |
| // success: function(html){ | |
| // $(html).find("a[href*=twitter]:first").attr("href"); | |
| // } | |
| // }); | |
| // }) | |
| $("body").append($("<textarea></textarea>")) | |
| $("textarea").val(JSON.stringify(json)); | |
| console.log(json); | |
| console.log(no_tw); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment