3
1

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 1 year has passed since last update.

概要

paiza.ioでelixirやってみた。
練習問題やってみた。

練習問題

htmlをスクレイピングせよ。

参考にしたページ

サンプルコード


:inets.start
:ssl.start

url = "https://qiita.com/advent-calendar/2022/elixir"
url = String.to_charlist(url)
{:ok, {_status, _headers, body}} = :httpc.request(url)
body = IO.iodata_to_binary(body)
|> IO.iodata_to_binary
|> String.split("encryptedId")
|> Enum.map(fn s -> 
    Regex.named_captures(~r/"user":{"urlName":"(?<user>.*?)",/, s) 
end)
|> Enum.slice(2..-1//1)
|> Enum.map(fn %{"user" => user} -> 
    user 
end)
|> Enum.frequencies
|> Enum.sort_by(fn {_user, cnt} -> 
    cnt 
end, :desc)
|> IO.inspect
|> Enum.reduce(0, fn {_user, cnt}, sum -> 
    sum + cnt 
end)
|> IO.puts


実行結果

[
  {"torifukukaiou", 42},
  {"RyoWakabayashi", 41},
  {"zacky1972", 25},
  {"mnishiguchi", 24},
  {"piacerex", 11},
  {"the_haigo", 10},
  {"ShigeItoEx", 7},
  {"GeekMasahiro", 7},
  {"Yoosuke", 7},
  {"nako_sleep_9h", 5},
  {"miwacchi", 5},
  {"t-yamanashi", 5},
  {"westbaystars", 3},
  {"k-j-y", 3},
  {"koga1020", 3},
  {"ta_to_jp", 2},
  {"kyawaguchi", 1},
  {"mokichi", 1},
  {"Gsann", 1},
  {"a_utsuki", 1},
  {"def_elixir", 1},
  {"kikuyuta", 1},
  {"ohr486", 1},
  {"hisaway", 1},
  {"nanbut14", 1},
  {"Goody27", 1},
  {"Alicesky2127", 1},
  {"pojiro", 1},
  {"tomoaki-kimura", 1},
  {"koyo-miyamura", 1},
  {"GKBR", 1},
  {"MzRyuKa", 1},
  {"tamanugi", 1},
  {"myasu", 1},
  {"tuchiro", 1}
]
219

成果物

以上。

3
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?