طريقة زحف نظام الإفصاح الإلكتروني Dart للاستثمار الكمي للمخزون

طريقة زحف نظام الإفصاح الإلكتروني Dart للاستثمار الكمي للمخزون

KissCuseMe
2025-03-11
7

سأشرح كيفية زحف البيانات المالية في نظام الكشف عن إلكترونيات DART. استخدم طلبات Python ، مكتبة BeautifulSoup ، و Pandas.ومع ذلك ، كن حذرًا من تغيير بنية موقع الويب عند استخدامه بالفعل ، ويمكن تحميل الطلبات المفرطة على الخادم.


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: رمز العنصر (على سبيل المثال ، Samsung Electronics = 005930)
    • report_type: A001 (السنوي) ، A002 (نصف سنوي) ، A003 (فرع)
    • يقتصر نطاق التاريخ على start_date و end_date.
  • قائمة التقارير الزحف:
    • استدعاء واجهة برمجة تطبيقات البحث عن الكشف عن DART واحصل على قائمة بالتقارير.
    • بعد تحليل HTML مع BeautifulSoup ، استخراج عنوان التقرير ورابط.
  • استخراج ملف Excel:
    • في كل صفحة من صفحة التقرير ، ابحث عن رابط ملف XBRL وتنزيله بتنسيق XBRL.
    • اقرأ ملف Excel إلى Pandas وتحويله إلى DataFrame.
  • حذر
    • معالجة المحتوى الديناميكي: يمكن تحميل بعض الصفحات ديناميكيًا مع JavaScript. قد تحتاج إلى استخدام هذا -selenium.
    • البيانات -التنسيق: قد يكون بنية ملف Excel مختلفة لكل شركة ، لذلك تحتاج إلى إضافة منطق تعيين العمود.
    • التقييد القانوني: يجب أن تمتثل لشروط وشروط Dart عند الزحف.

بناءً على هذا الرمز ، يمكنك تنفيذ معالجة بيانات إضافية ومنطق تحليل الكمية.

الأسهم
الكمية
الاستثمار
الزحف
دارت

0

جدول المحتويات

  • 1. تركيب المكتبة اللازمة
  • 2. بحث الكشف عن DART وبيان مالي يزحف مثال
  • 3. وصف الرمز
هذا المنشور هو جزء من أنشطة برنامج شركاء كوبانغ، ويتم استلام عمولة وفقًا لذلك.

شروط الخدمةسياسة الخصوصيةالدعم
© 2025
لو كنت أعلم مسبقًا، لكانت الأمور أفضل
All rights reserved.