rairo commited on
Commit
779b2e7
Β·
verified Β·
1 Parent(s): 8e1c813

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +9 -20
src/streamlit_app.py CHANGED
@@ -36,9 +36,6 @@ if 'chat_history' not in st.session_state:
36
  # Basketball-Reference Data Fetching Utilities
37
  # β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
38
 
39
- # Basketball-Reference Data Fetching Utilities
40
- # β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
41
-
42
  import requests
43
  import pandas as pd
44
  import streamlit as st
@@ -76,7 +73,7 @@ def parse_table(html, table_id=None):
76
  """
77
  if not html:
78
  return pd.DataFrame()
79
-
80
  soup = BeautifulSoup(html, "html.parser")
81
  tbl_html = ""
82
 
@@ -87,22 +84,14 @@ def parse_table(html, table_id=None):
87
  tbl_html = str(tbl)
88
  else:
89
  # If not found directly, search for it within HTML comments
90
- # Basketball-Reference often comments out tables
91
- comment_pattern = re.compile(
92
- r'<!--.*?<table[^>]*?id=["\']' + re.escape(table_id) + r'["\'][^>]*?>.*?</table>.*?-->',
93
- re.DOTALL | re.IGNORECASE
94
- )
95
- comment_match = comment_pattern.search(html)
96
- if comment_match:
97
- # Extract the content of the comment
98
- comment_content = comment_match.group(0)
99
- # Remove the comment tags
100
- comment_content = comment_content.replace('<!--', '').replace('-->', '')
101
- # Parse the comment content as new HTML
102
- comment_soup = BeautifulSoup(comment_content, 'html.parser')
103
- tbl = comment_soup.find('table', {'id': table_id})
104
- if tbl:
105
- tbl_html = str(tbl)
106
  else:
107
  # fallback: first table on page (only if no table_id specified)
108
  first = soup.find("table")
 
36
  # Basketball-Reference Data Fetching Utilities
37
  # β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
38
 
 
 
 
39
  import requests
40
  import pandas as pd
41
  import streamlit as st
 
73
  """
74
  if not html:
75
  return pd.DataFrame()
76
+
77
  soup = BeautifulSoup(html, "html.parser")
78
  tbl_html = ""
79
 
 
84
  tbl_html = str(tbl)
85
  else:
86
  # If not found directly, search for it within HTML comments
87
+ comments = soup.find_all(string=lambda text: isinstance(text, Comment))
88
+ for comment in comments:
89
+ if table_id in comment:
90
+ comment_soup = BeautifulSoup(comment, 'html.parser')
91
+ tbl = comment_soup.find('table', {'id': table_id})
92
+ if tbl:
93
+ tbl_html = str(tbl)
94
+ break
 
 
 
 
 
 
 
 
95
  else:
96
  # fallback: first table on page (only if no table_id specified)
97
  first = soup.find("table")