Created
June 30, 2011 12:00
-
-
Save hal99/1056102 to your computer and use it in GitHub Desktop.
「ログ・ホライズン」を青空文庫形式のテキストファイルに変換する
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
require "rubygems" | |
require "open-uri" | |
require "nokogiri" | |
puts "ログ・ホライズン" | |
puts "橙乃ままれ" | |
puts "\n" | |
(1..54).each do |i| | |
puts %Q!\nThread #{sprintf("%03d",i)}\n\n! | |
doc = Nokogiri::HTML(open("http://ncode.syosetu.com/n8725k/#{i}/").read) | |
doc.xpath("//div[@id='novel_view']").inner_text.each do |line| | |
line = line.gsub( / /, '' ).gsub( /%/, '%' ) unless line.length == 0 | |
puts line | |
end | |
sleep 10 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ruby1.8.7で動かしています。スクリプトはただただしさんの「まおゆう」を青空文庫形式のテキストファイルに変換するからアイディアを頂きました。使い方は以下の通りで動作できると思います。PDFへの変換は、「青空キンドル」さんのサービスを利用しています。
$ ruby loghoraizun2aozora.rb > loghoraizun.txt
$ curl --data-urlencode text@loghoraizun.txt -d s=m -o loghoraizun.pdf http://a2k.aill.org/download.cgi