Skip to content

Instantly share code, notes, and snippets.

@pooza
Last active January 9, 2022 05:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pooza/c623b8771aa63193c12e3a5b19ac2705 to your computer and use it in GitHub Desktop.
Save pooza/c623b8771aa63193c12e3a5b19ac2705 to your computer and use it in GitHub Desktop.
デパプリニュースページをJSON化
#!/usr/bin/env ruby
dir = File.expand_path('..', __dir__)
$LOAD_PATH.unshift(File.join(dir, 'app/lib'))
ENV['BUNDLE_GEMFILE'] = File.join(dir, 'Gemfile')
require 'mulukhiya'
ROOT_URL = 'https://www.toei-anim.co.jp/tv/delicious-party_precure/'.freeze
SOURCE_URL = 'https://www.toei-anim.co.jp/tv/delicious-party_precure/news/'.freeze
Dir.chdir(dir)
http = Mulukhiya::HTTP.new
entries = []
http.get(SOURCE_URL).body.nokogiri.xpath('//ul[@class="m-list-topics"]//a').each do |node|
next unless link = node.attribute('href')
entry = {
link: Ginseng::URI.fix(ROOT_URL, link.value).to_s,
title: node.search('dd').inner_text,
date: Time.parse(node.search('dt').inner_text),
}
if image = node.search('img')
entry[:enclosure] = {
url: Ginseng::URI.fix(ROOT_URL, image.attribute('src').value).to_s,
}
end
entries.push(entry)
rescue => e
warn e.message
end
puts entries.to_json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment