Skip to content

Instantly share code, notes, and snippets.

@uni8inu
Created December 7, 2016 23:52
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 uni8inu/a3d7494392be7a98747aeb33b874a7e7 to your computer and use it in GitHub Desktop.
Save uni8inu/a3d7494392be7a98747aeb33b874a7e7 to your computer and use it in GitHub Desktop.
なろうディベロッパー Python3版サンプルコード
import json
from urllib.request import urlopen
import gzip
#sample get
#refer to: http://dev.syosetu.com/man/sample01/
#APIのURL(パラメーターを指定してください)
url = "http://api.syosetu.com/novelapi/api/?out=json&lim=100&gzip=5"
#APIを取得
response = urlopen(url)
#解凍する
with gzip.open(response,"rt",encoding="utf-8") as f:
j_raw = f.read() # caution : memory over error
#JSONデコード
jObj = json.loads(j_raw)
#jObj0番目はallcountなので1番目から処理
for a_novel in jObj[1:]:
#titleの表示
title = a_novel['title']
print(title)
#あらすじの表示
story = a_novel['story']
print(story)
#小説へのリンク作成
ncode = a_novel['ncode']
link = "http://ncode.syosetu.com/{}/".format(ncode.lower())
print(link)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment