Spaces:
Sleeping
Sleeping
File size: 1,455 Bytes
fd35c9f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
import requests
from bs4 import BeautifulSoup
import pandas as pd
import gradio as gr
# URL ์ค์
KOSDAQ_URL = "https://finance.naver.com/sise/sise_rise.naver?sosok=1"
def scrape_kosdaq_info():
# ์์ฒญ ๋ฐ HTML ํ์ฑ
response = requests.get(KOSDAQ_URL)
response.raise_for_status()
soup = BeautifulSoup(response.text, "html.parser")
# ๋ฐ์ดํฐ ์ถ์ถ
rows = soup.select("table.type_2 tbody tr")
data = []
for row in rows:
# ์ข
๋ชฉ๋ช
์ถ์ถ
name_tag = row.select_one("a.tltle")
if name_tag:
name = name_tag.text.strip()
# ์ข
๋ชฉ ์ฝ๋ ์ถ์ถ
code = name_tag["href"].split("code=")[-1]
data.append({"์ข
๋ชฉ๋ช
": name, "์ข
๋ชฉ์ฝ๋": code})
# DataFrame์ผ๋ก ๋ณํ
df = pd.DataFrame(data)
return df
def display_kosdaq_info():
# ๋ฐ์ดํฐ ์คํฌ๋ํ ๋ฐ ์ถ๋ ฅ
df = scrape_kosdaq_info()
return df
# ๊ทธ๋ผ๋์ค UI ์ ์
def kosdaq_ui():
def get_table():
# ํ
์ด๋ธ ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐ
df = scrape_kosdaq_info()
return df
interface = gr.Interface(
fn=get_table,
inputs=None,
outputs="dataframe",
title="์ฝ์ค๋ฅ ์ข
๋ชฉ ์ ๋ณด ์คํฌ๋ํผ",
description="๋ค์ด๋ฒ ์ฆ๊ถ ์ฌ์ดํธ์์ ์ฝ์ค๋ฅ ์ข
๋ชฉ ์ ๋ณด๋ฅผ ์คํฌ๋ํํ์ฌ ํ์ํฉ๋๋ค."
)
interface.launch()
# ์คํ
if __name__ == "__main__":
kosdaq_ui()
|