Help us understand the problem. What is going on with this article?

PythonでEDINETへアクセスするサンプル(仕掛中)

PythonでEDINETへアクセスするサンプル(仕掛中)

Qiitaへ投稿する練習を兼ねてるのでまだ仕掛中だけで投稿

ednet_XBRL.py
import requests
from bs4 import BeautifulSoup  ##スクレイピング用
import json  ##Python3 で JSON 形式のデータを扱う方法
import re
import os
from xbrl_proc import read_xbrl_from_zip

def get_Edinet_doclist(date:str) -> list:
  """
  get_Edinet_doclist
  Edinetからドキュメント一覧のLISTを取得しリターンする。

  Args:
  <date> <str>:
    提出した日付

  Returns:
   <type>:list
     ドキュメント一覧リスト

  """
  retdoclist = []
  # 書類一覧APIのエンドポイント
  url = "https://disclosure.edinet-fsa.go.jp/api/v1/documents.json"

  # 書類一覧APIのリクエストパラメータ
  params = {
    "date" : date,
    "type" : 2
  }

  # 書類一覧APIの呼び出し
  res = requests.get(url, params=params, verify=False)
  jsn = json.loads(res.text)

  # レスポンス(JSON)の表示
  print(type(jsn))
  print(len(jsn))
  print(jsn.keys())
  #print(jsn)

  for value in jsn['results']:
    if isinstance(value['secCode'],str) and isinstance(value['docTypeCode'],str) and value['docTypeCode']=='120':
        retdoclist.append(value)

  return retdoclist



def fn_getzipfile(docid:str) -> str:
  url2 = "https://disclosure.edinet-fsa.go.jp/api/v1/documents/" + docid
  params2 = { "type" : 1}
  fname = docid + ".zip"
  print('■'+ str(fname))

  # EDINET API_2:提出書類のZIP取得
  res = requests.get(url2, params=params2)

  # ファイルへ出力
  zip_fname = os.getcwd() + "\\" + fname
  if res.status_code == 200:
     with open(zip_fname, 'wb') as f:
      for chunk in res.iter_content(chunk_size=1024):
        f.write(chunk)
      return zip_fname

#関数呼び出しとメイン処理
getlist = get_Edinet_doclist("2019-06-19")

for value in getlist:
  if isinstance(value['filerName'],str):
    match = re.search(r'本田技研',value['filerName'])
    if match:
      print('証券コード:' + value['secCode'][0:4])
      print('会社名:' + value['filerName'])
      zip_fname = fn_getzipfile(value['docID'])
      df_list = read_xbrl_from_zip(zip_fname)
      for df in df_list:
        print(df)

引用

太字

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away