Skip to content

Instantly share code, notes, and snippets.

@syusui-s
Created September 25, 2013 10:04
Show Gist options
  • Select an option

  • Save syusui-s/6697599 to your computer and use it in GitHub Desktop.

Select an option

Save syusui-s/6697599 to your computer and use it in GitHub Desktop.
某大学のWebサイトから自分の時間割をスクレイピングするJavaScriptコード。時間割表示して、ブラウザのコンソールに打ち込むと、文字列が返ってきてくれるはず。ChromeとFirefoxで動作確認済み。
var schedule = new Array();
rows=document.getElementsByClassName("schedule_box")[0].rows;
for(var i=1;i<rows.length;i+=2){
cells=rows[i].cells;
var days=new Array();
for(var j=1;j<cells.length;j++){
days.push(cells[j].textContent.replace(/\s/g, ''));
}
schedule.push(days);
}
for(var i=0;i<schedule.length;i++){
var days = schedule[i];
for(var j=0;j<days.length;j++){
days[j]='"'+days[j].toString()+'"'
}
schedule[i] = '['+days.toString()+']'
}
'['+schedule.toString()+']'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment