Last active
January 9, 2022 05:19
-
-
Save pooza/c623b8771aa63193c12e3a5b19ac2705 to your computer and use it in GitHub Desktop.
デパプリニュースページをJSON化
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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