3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

テーブルのデータをスクレイピングする

Posted at

jQueryのテーブル関係の練習
以下coffee、表現はEmmet

テーブルヘッダーを取ってスキーマを作る

tables = $(「目的のテーブル、もしくは目的のテーブルを含む配列」)[0]

初期状態:table>thead(>th>td)+tbody(>tr*100)

process01 = tables.rows

(tr>td*5)*100

tableの中の配列を得るのがrows
theadもtr>tdに変換されたようになって、すべてrowsとして扱えるようになる

process02 = tables.rows[0]

tr>td*5

process03 = tables.rows[0].cells

[td*5]

trの中のtd配列を取るのがcells

_.each process03, (cell, index) -> console.log $(cell).html()

ヘッダーが順番に出てくる

うむ、取れそう

データ取得

これでスキーマに定義したものでデータをとっていく

_.each tables.rows, (row, rIndex) ->
	if rIndex is 0 then return
	_.each row.cells, (cell, cIndex) ->
		console.log "(" + cIndex + ", " + rIndex + ") = " + $(cell).html()

インデックスをスキーマに対応させれば保存できますね。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?