JERNGOC commited on
Commit
f2f8907
·
verified ·
1 Parent(s): bfe653b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ from bs4 import BeautifulSoup
3
+ import requests
4
+ import gradio as gr
5
+
6
+ def scrape_data():
7
+ url = "https://web.hosp.ncku.edu.tw/nckm/Bedstatus/BedStatus.aspx"
8
+ response = requests.get(url)
9
+ soup = BeautifulSoup(response.text, "html.parser")
10
+ table = soup.find("table", {"id": "GV_EmgInsure"})
11
+ rows = table.find_all("tr")
12
+ columns = [th.text.strip() for th in rows[0].find_all("th")]
13
+ data = []
14
+ for row in rows[1:]:
15
+ row_data = [td.text.strip() for td in row.find_all("td")]
16
+ data.append(row_data)
17
+ df = pd.DataFrame(data, columns=columns)
18
+ return df
19
+
20
+ def gradio_interface():
21
+ return gr.Interface(fn=scrape_data, inputs=[], outputs="dataframe").launch()
22
+
23
+ if __name__ == "__main__":
24
+ gradio_interface()