Created
February 4, 2020 05:20
-
-
Save YusukeOba/d9d930b3205e00dae7456a91c798fa02 to your computer and use it in GitHub Desktop.
小説家になろうのAPIから各種情報を抽出する
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
# ★の数/評価者数で割って平均値を知りたかった | |
import json | |
from collections import OrderedDict | |
import requests | |
from bs4 import BeautifulSoup | |
import csv | |
import time | |
# ひとまず500位まで | |
rank_fetch_limit = 500 | |
f = open('book_reviews.csv', 'w') | |
writer = csv.writer(f, lineterminator='\n') | |
# ランキングから小説の評価情報を抜き出し | |
content = requests.get("https://api.syosetu.com/novelapi/api/?lim=" + str(rank_fetch_limit) + "&order=hyoka&out=json").content | |
narou_rankings = json.loads(content) | |
# allcountは不要 | |
narou_rankings.pop(0) | |
for narou_novel in narou_rankings: | |
# 小説のタイトル | |
title = narou_novel["title"] | |
# ジャンルコード | |
genre_code = narou_novel["genre"] | |
# 評価点 | |
all_point = narou_novel["all_point"] | |
# 評価者の数 | |
hyoka_cnt = narou_novel["all_hyoka_cnt"] | |
csv_row = [title, genre_code, all_point, hyoka_cnt] | |
writer.writerow(csv_row) | |
print("proceeded: " + title + "\n") | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment