LoginSignup
14
10

More than 5 years have passed since last update.

wikipedia の api をつかって、記事のアクセスを見る

Last updated at Posted at 2017-09-24

wikipedia の記事へのアクセスログ

簡単にとれるのでつくってみました。タブ区切りで結果が出力されるので、エクセルなどにはりつけてすぐにグラフ化できます。記事の題名かえて適宜ためしてみてください。


#!/usr/bin/env python
# -*- encoding:utf-8 -*-
import requests
import json
import urllib

t1='{x_type}/{x_lang}.wikipedia/all-access/all-agents/{x_article}/daily/{ymd_from}/{ymd_to}'
x_type='https://wikimedia.org/api/rest_v1/metrics/pageviews/per-article'

# 英語 Shinzō_Abe
#x_article='Shinz%C5%8D_Abe'
#x_lang = 'en' # 英語の指定

x_article = urllib.parse.quote('前川喜平') # 
x_lang = 'ja' # 日本語の指定
ymd_from='2017050100' # 日付開始
ymd_to='2017053000'   # 日付終わり

req = requests.get(t1.format(ymd_from=ymd_from,x_lang=x_lang,x_type=x_type,x_article=x_article,
                             ymd_to=ymd_to))#req.text
for one in json.loads(req.text)['items']:
    print(one['timestamp'] + "\t" + str(one['views']) )

前川喜平

の9月のアクセスログです。グラフ化しました。

chart_20170924_1.png

14
10
2

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
14
10