ダート電子開示システム株式量投資のためのクロール方法

ダート電子開示システム株式量投資のためのクロール方法

KissCuseMe
2025-03-11
7

DART Electronics開示システムで財務諸表をクロールする方法を説明します。 Pythonのリクエスト、BeautifulSoup、およびPandas Libraryを使用してください。ただし、実際に使用されている場合はWebサイトの構造を変更することに注意してください。また、サーバーに過剰なリクエストをロードできます。


1。必要なライブラリのインストール

pip install requests beautifulsoup4 pandas openpyxl

2。DART開示検索と財務諸表のクロール例

import requests
from bs4 import BeautifulSoup
import pandas as pd
from urllib.parse import urljoin

# Search Criteria (e.g., Samsung Electronics (005930) Annual Report)
COMPANY_CODE = "005930"  # Stock Code
START_DATE = "20230101"  # Search Start Date (YYYYMMDD)
END_DATE = "20231231"    # Search End Date (YYYYMMDD)
REPORT_TYPE = "A001"     # A001: Annual Report, A002: Semi-Annual Report, A003: Quarterly Report

# DART Disclosure Search URL
SEARCH_URL = "http://dart.fss.or.kr/dsab001/search.ax"

def get_report_list():
    """Function to fetch the list of DART disclosure reports"""
    params = {
        "currentPage": 1,
        "maxResults": 10,
        "businessCode": COMPANY_CODE,
        "startDate": START_DATE,
        "endDate": END_DATE,
        "reportName": REPORT_TYPE
    }
    response = requests.get(SEARCH_URL, params=params)
    soup = BeautifulSoup(response.text, 'html.parser')
    return soup.select(".table_list tr")[1:]  # Extract rows excluding the header

def extract_excel_url(report_url):
    """Function to extract the Excel file URL from the report page"""
    response = requests.get(report_url)
    soup = BeautifulSoup(response.text, 'html.parser')
    excel_link = soup.select_one("a[href*='download.xbrl']")
    if excel_link:
        return urljoin(report_url, excel_link['href'])
    return None

def download_excel(url):
    """Function to download the Excel file and convert it into a DataFrame"""
    response = requests.get(url)
    with open("temp.xlsx", "wb") as f:
        f.write(response.content)
    return pd.read_excel("temp.xlsx", engine='openpyxl')

# Main Execution
if __name__ == "__main__":
    reports = get_report_list()
    for idx, report in enumerate(reports[:3]):  # Process up to 3 reports
        # Extract report title and link
        title = report.select_one("td:nth-child(3) a").text.strip()
        report_url = urljoin(SEARCH_URL, report.select_one("td:nth-child(3) a")['href'])
        
        print(f"[{idx+1}] Extracting data from {title}...")
        
        # Extract Excel file URL and download
        excel_url = extract_excel_url(report_url)
        if excel_url:
            df = download_excel(excel_url)
            print(df.head())  # Check the data
        else:
            print("Excel file not found.")

3。コードの説明

  • 検索条件設定:
    • company_code:sアイテムコード(例:Samsung Electronics = 005930)
    • Report_Type:A001(Annual)、A002(Semi -Annual)、A003(Branch)
    • 日付範囲はstart_dateとend_dateに制限されています。
  • レポートリストクロール:
    • DART開示検索APIを呼び出して、レポートのリストを取得します。
    • HTMLをBeautifulSoupで解析した後、レポートのタイトルとリンクを抽出します。
  • Excelファイル抽出:
    • 各レポートページで、XBRL形式のXBRLファイルリンクを見つけてダウンロードします。
    • Excelファイルをパンダに読んで、データフレームに変換します。
  • 注意
    • 動的コンテンツ処理:一部のページは、JavaScriptで動的にロードできます。 これを使用する必要があるかもしれません - セレニウム。
    • Data -Consolidation:Excelファイル構造は各企業で異なる場合があるため、列マッピングロジックを追加する必要があります。
    • 法的制限:rawうときは、DARTの条件に従わなければなりません。

このコードに基づいて、追加のデータ前処理と量子分析ロジックを実装できます。

在庫
Quant
Investment
Crawling
Dart

0

目次

  • 1。必要なライブラリのインストール
  • 2。DART開示検索と財務諸表のクロール例
  • 3。コードの説明
この投稿は、クパンパートナーズの活動の一環として、一定額の手数料を受け取ります。

利用規約個人情報取扱方針サポート
© 2025
あらかじめ知っていたら良かったでしょう
All rights reserved.