LoginSignup
18
18

More than 5 years have passed since last update.

Pixiv小説検索APIの結果を元に小説本文を取得する

Last updated at Posted at 2014-04-20

概要

Pixiv小説検索APIの結果をCSV形式で取得し、
そのCSVファイルを元に小説本文をテキスト形式で取得する。

処理

01.Pixiv小説検索APIの結果をCSV形式で取得

-> Pixiv検索結果をCSVダウンロードするHTMLファイルを用意した
 ※CSVファイルの名前はINPUT.csvに変える。

02.取得CSVファイルの同階層に、下記Rubyコードを配置

pxcsv2novel.rb
# encoding: utf-8

require 'csv'
require 'uri'
require 'net/http'
require 'fileutils'

#入力ファイル名
INPUT_CSV = ARGV[0] || 'INPUT.csv'

path = Time.now.strftime("%y%m%d%H%M%S")
FileUtils.mkdir_p(path)

CSV.foreach(INPUT_CSV, encoding: "UTF-8") do |row|
  sleep(rand(3) + 6)
  if (0 < row[0].length) then
    uri = URI.parse("http://spapi.pixiv.net/iphone/novel_text.php?id=" + row[0])
    text = Net::HTTP.get(uri)
    open(path + '/' + (row[0] + ".txt"), "wb") {|f|
      f.write(text)
    }
  end
end

puts "end!"

出力イメージ

yyMMddhhmmss(出力フォルダ)
 |ー0000001.txt(出力テキストファイル)
 |ー0000002.txt
 |ー0000003.txt
 |ー etc...

関連ページ

-> Rで自然言語処理。Pixiv小説で単語別の出現数を調べる
-> ニコニコ大百科データからMeCab辞書を生成する
-> Rで文書分類器。未来設定のラブライブ!百合小説を抽出する

18
18
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
18
18