Skip to content

Commit 25b2793

Browse files
committed
wip
1 parent 2d39342 commit 25b2793

3 files changed

Lines changed: 32 additions & 5 deletions

File tree

bdshare/stock/market.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ def get_market_depth_data(symbol: str, retry_count: int = 3, pause: float = 0.2)
226226
matrix[m + 1]: _safe_num(newcols[1].text, int),
227227
})
228228

229-
if not result:
230-
raise BDShareError(f"No market depth data parsed for {symbol}.")
229+
# if not result:
230+
# raise BDShareError(f"No market depth data parsed for {symbol}.")
231231
return pd.DataFrame(result)
232232

233233

bdshare/util/helper.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,34 @@ def _fetch_table(
152152
except Exception:
153153
soup = BeautifulSoup(r.content, "html.parser")
154154

155-
attrs = {"class": table_class, "_id": table_id} if table_class else {}
156-
table = soup.find("table", attrs=attrs)
155+
# attrs = {"class": table_class, "_id": table_id} if table_class else {}
156+
# table = soup.find("table", attrs=attrs)
157+
158+
table = None
159+
160+
if table_class or table_id:
161+
attrs: Dict[str, str] = {}
162+
if table_class:
163+
attrs["class"] = table_class
164+
165+
if table_id:
166+
# Primary: standard HTML id attribute
167+
table = soup.find("table", attrs={**attrs, "id": table_id})
168+
# Fallback: legacy _id alias used by some BS4 internals
169+
if table is None:
170+
table = soup.find("table", attrs={**attrs, "_id": table_id})
171+
else:
172+
table = soup.find("table", attrs=attrs)
173+
else:
174+
table = soup.find("table")
157175

158176
if table is None:
159-
detail = f" with class {table_class!r}" if table_class else ""
177+
parts = []
178+
if table_class:
179+
parts.append(f"class={table_class!r}")
180+
if table_id:
181+
parts.append(f"id={table_id!r}")
182+
detail = " with " + ", ".join(parts) if parts else ""
160183
raise BDShareError(f"Table{detail} not found at {url}")
161184

162185
return table

bdshare/util/vars.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@
1818
DSE_MARKET_DEPTH_REFERER_URL = "mkt_depth_3.php"
1919

2020
DSEX_INDEX_VALUE = "dseX_share.php"
21+
22+
DSE_SECTOR_PERF_URL = "sector_performance.php"
23+
DSE_TOP_GAINERS_URL = "top_gainers.php"
24+

0 commit comments

Comments
 (0)