LoginSignup
0
0

More than 3 years have passed since last update.

テーブルタグからほしい情報を取り出す

Last updated at Posted at 2020-09-17

新型コロナウイルス感染症に関する報道発表資料(発生状況、国内の患者発生、海外の状況、その他)
https://www.mhlw.go.jp/stf/seisakunitsuite/bunya/0000121431_00086.html

データサンプル
https://www.mhlw.go.jp/stf/newpage_13640.html


const html = `(上のテーブルをコピペする)`

// カンマ区切りの数字のカンマ削除、タブを,に変換して CSVライクにする
const csv = html.replaceAll(',', '').replaceAll('\t', ',')
// 改行ごとに配列に変換
const arr = csv.split('\n')
// ほしいデータに整形
const data = arr.map(d => {
  const [name, a,b ] = d.split(',')
  return {name, a: parseInt(a, 10), b: parseInt(b, 10)}
})
// 感染者数の降順にする
data.sort((a, b) => -(a.a - b.a))
0
0
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
0
0