anna-cat51 / menu_memoire

0 stars 0 forks source link

スクレイピング先を増やす #83

Open anna-cat51 opened 8 months ago

anna-cat51 commented 8 months ago
require 'uri'

def process_url(url)
  uri = URI.parse(url)
  host = uri.host

  case host
  when 'oceans-nadia.com'
    # Aの処理
    process_a
  when 'www.kikkoman.co.jp'
    # Bの処理
    process_b
  when 'delishkitchen.tv'
    # Cの処理
    process_c
  else
    # その他のURLの処理
    process_default
  end
end

def process_a
  # Aの処理内容
end

def process_b
  # Bの処理内容
end

def process_c
  # Cの処理内容
end

def process_default
  # その他のURLの処理内容
end

のように、レシピサイトによって要素名が違うためuriでホストURLから判断し、caseで処理を分けて実装する。

候補レシピサイト