|
|
|
@ -5,7 +5,9 @@ S&P 500 / Nasdaq 100 구성 종목을 Wikipedia에서 조회
|
|
|
|
|
|
|
|
|
|
|
|
import asyncio
|
|
|
|
import asyncio
|
|
|
|
import logging
|
|
|
|
import logging
|
|
|
|
|
|
|
|
from io import StringIO
|
|
|
|
from typing import Optional
|
|
|
|
from typing import Optional
|
|
|
|
|
|
|
|
from urllib.request import Request, urlopen
|
|
|
|
|
|
|
|
|
|
|
|
import pandas as pd
|
|
|
|
import pandas as pd
|
|
|
|
|
|
|
|
|
|
|
|
@ -41,7 +43,10 @@ class IndexConstituentsService:
|
|
|
|
industry_col = config["industry_col"]
|
|
|
|
industry_col = config["industry_col"]
|
|
|
|
|
|
|
|
|
|
|
|
logger.info(f"Fetching Wikipedia tables from {url}")
|
|
|
|
logger.info(f"Fetching Wikipedia tables from {url}")
|
|
|
|
tables = pd.read_html(url, flavor="lxml")
|
|
|
|
req = Request(url, headers={"User-Agent": "Mozilla/5.0 (compatible; StockOracle/1.0)"})
|
|
|
|
|
|
|
|
with urlopen(req, timeout=25) as resp:
|
|
|
|
|
|
|
|
html = resp.read().decode("utf-8")
|
|
|
|
|
|
|
|
tables = pd.read_html(StringIO(html), flavor="lxml")
|
|
|
|
|
|
|
|
|
|
|
|
# Try configured table index first
|
|
|
|
# Try configured table index first
|
|
|
|
df = None
|
|
|
|
df = None
|
|
|
|
|