sintamar commited on
Commit
cfac583
·
verified ·
1 Parent(s): 7c33c47

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -47
app.py CHANGED
@@ -26,50 +26,13 @@ def visualize(url):
26
  # Fetch and display the website content
27
  with st.spinner("loading website data ..."):
28
  # innerHTML = get_innerHTML(url)
29
- html_content, xdataframe, baris = take_webdata(url)
30
  #st.subheader("Website title:")
31
- if baris:
32
- st.code(baris, language='html')
33
- data = []
34
- for row in baris:
35
- rank = row.select_one(".tableCellRank")
36
- team = row.select_one(".tableCellParticipant__name")
37
- mp = row.select_one("span.table__cell:nth-of-type(3)")
38
- w = row.select_one("span.table__cell:nth-of-type(4)")
39
- d = row.select_one("span.table__cell:nth-of-type(5)")
40
- l = row.select_one("span.table__cell:nth-of-type(6)")
41
- g = row.select_one(".table__cell--score")
42
- sg = row.select_one(".table__cell--goalsForAgainstDiff")
43
- pts = row.select_one(".table__cell--points")
44
-
45
- data.append({
46
- "Peringkat": rank.text.strip() if rank else "",
47
- "Tim": team.text.strip() if team else "",
48
- "Main": mp.text.strip() if mp else "",
49
- "Menang": w.text.strip() if w else "",
50
- "Seri": d.text.strip() if d else "",
51
- "Kalah": l.text.strip() if l else "",
52
- "Gol": g.text.strip() if g else "",
53
- "Selisih Gol": sg.text.strip() if sg else "",
54
- "Poin": pts.text.strip() if pts else ""
55
- })
56
-
57
- # === 5. Buat DataFrame ===
58
- df = pd.DataFrame(data)
59
- st.dataframe(df)
60
  else:
61
- st.warning("Rows tidak ditemukan.")
62
- if xdataframe:
63
- #st.info(html_content)
64
-
65
- # Konversi tabel HTML ke DataFrame Pandas
66
- #df = pd.read_html(str(parse_element))[0]
67
- #st.dataframe(df) # tampilkan tabel dengan format rapi Streamlit
68
- st.components.v1.html(str(xdataframe), height=600, scrolling=True)
69
- # === 6. Tampilkan di Streamlit ===
70
- #st.dataframe(xdataframe)
71
- else:
72
- st.warning("Tabel tidak ditemukan.")
73
 
74
  except Exception as e:
75
  st.error(f"Error: {e}")
@@ -84,15 +47,30 @@ def take_webdata(url):
84
  wd = webdriver.Chrome(options=options)
85
  wd.set_window_size(1080, 720) # Adjust the window size here
86
  wd.get(url)
87
- wd.implicitly_wait(5)
88
  # Get the page title
89
  page_title = wd.title
90
  #screenshot = wd.get_screenshot_as_png()
91
- WebDriverWait(wd, 20).until(EC.presence_of_element_located((By.ID, "tournament-table")))
92
  html = wd.execute_script("return document.documentElement.outerHTML;")
93
  soup = BeautifulSoup(html, "html.parser")
94
- div_find = soup.find("div", id="tournament-table", class_="tournament-table-standings")
95
- rows = div_find.select("div[class*=ui-table__row]")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
 
97
  #rows = div_find.find("ui-table__row ") if div_find else None
98
  #rows = soup.find("div", class_="ui-table__row ")
@@ -104,7 +82,7 @@ def take_webdata(url):
104
  if wd:
105
  wd.quit()
106
 
107
- return html , div_find, rows
108
 
109
  if __name__ == "__main__":
110
  main()
 
26
  # Fetch and display the website content
27
  with st.spinner("loading website data ..."):
28
  # innerHTML = get_innerHTML(url)
29
+ html_content, xtarget_dropdown, xurl = take_webdata(url)
30
  #st.subheader("Website title:")
31
+ if xtarget_dropdown:
32
+ st.code(xtarget_dropdown, language='html')
33
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  else:
35
+ st.warning("tidak ditemukan.")
 
 
 
 
 
 
 
 
 
 
 
36
 
37
  except Exception as e:
38
  st.error(f"Error: {e}")
 
47
  wd = webdriver.Chrome(options=options)
48
  wd.set_window_size(1080, 720) # Adjust the window size here
49
  wd.get(url)
50
+ wd.implicitly_wait(15)
51
  # Get the page title
52
  page_title = wd.title
53
  #screenshot = wd.get_screenshot_as_png()
54
+ #WebDriverWait(wd, 20).until(EC.presence_of_element_located((By.ID, "tournament-table")))
55
  html = wd.execute_script("return document.documentElement.outerHTML;")
56
  soup = BeautifulSoup(html, "html.parser")
57
+
58
+ target_dropdown = soup.find('div', class_='dropdown-menu', attrs={'aria-labelledby': 'navbar-match'})
59
+
60
+ if target_dropdown:
61
+ links = target_dropdown.find_all('a', class_='dropdown-item')
62
+
63
+ for link in links:
64
+ urlx = link.get('href')
65
+ text = link.get_text(strip=True)
66
+ #print(f"Text: {text}")
67
+ #print(f"URL: {url}")
68
+ #print("---")
69
+ else:
70
+ print("Dropdown menu tidak ditemukan")
71
+
72
+ #div_find = soup.find("div", id="tournament-table", class_="tournament-table-standings")
73
+ #rows = div_find.select("div[class*=ui-table__row]")
74
 
75
  #rows = div_find.find("ui-table__row ") if div_find else None
76
  #rows = soup.find("div", class_="ui-table__row ")
 
82
  if wd:
83
  wd.quit()
84
 
85
+ return html ,target_dropdown, urlx
86
 
87
  if __name__ == "__main__":
88
  main()