Spaces:
Running
Running
Update extract.py
Browse files- extract.py +27 -2
extract.py
CHANGED
|
@@ -23,13 +23,38 @@ def take_webdata(url):
|
|
| 23 |
soup = BeautifulSoup(html, "html.parser")
|
| 24 |
#div_find = soup.find("div", id="tournament-table", class_="tournament-table-standings")
|
| 25 |
#table_find = div_find.find("table") if div_find else None
|
| 26 |
-
tournament_div = soup.find("div",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
|
|
|
|
|
|
|
|
|
| 29 |
except WebDriverException as e:
|
| 30 |
return page_title
|
| 31 |
finally:
|
| 32 |
if wd:
|
| 33 |
wd.quit()
|
| 34 |
|
| 35 |
-
return html ,
|
|
|
|
| 23 |
soup = BeautifulSoup(html, "html.parser")
|
| 24 |
#div_find = soup.find("div", id="tournament-table", class_="tournament-table-standings")
|
| 25 |
#table_find = div_find.find("table") if div_find else None
|
| 26 |
+
tournament_div = soup.find("div", class_="ui-table__row ")
|
| 27 |
+
data = []
|
| 28 |
+
for row in rows:
|
| 29 |
+
rank = row.select_one(".tableCellRank")
|
| 30 |
+
team = row.select_one(".tableCellParticipant__name")
|
| 31 |
+
mp = row.select_one("span.table__cell:nth-of-type(3)")
|
| 32 |
+
w = row.select_one("span.table__cell:nth-of-type(4)")
|
| 33 |
+
d = row.select_one("span.table__cell:nth-of-type(5)")
|
| 34 |
+
l = row.select_one("span.table__cell:nth-of-type(6)")
|
| 35 |
+
g = row.select_one(".table__cell--score")
|
| 36 |
+
sg = row.select_one(".table__cell--goalsForAgainstDiff")
|
| 37 |
+
pts = row.select_one(".table__cell--points")
|
| 38 |
|
| 39 |
+
data.append({
|
| 40 |
+
"Peringkat": rank.text.strip() if rank else "",
|
| 41 |
+
"Tim": team.text.strip() if team else "",
|
| 42 |
+
"Main": mp.text.strip() if mp else "",
|
| 43 |
+
"Menang": w.text.strip() if w else "",
|
| 44 |
+
"Seri": d.text.strip() if d else "",
|
| 45 |
+
"Kalah": l.text.strip() if l else "",
|
| 46 |
+
"Gol": g.text.strip() if g else "",
|
| 47 |
+
"Selisih Gol": sg.text.strip() if sg else "",
|
| 48 |
+
"Poin": pts.text.strip() if pts else ""
|
| 49 |
+
})
|
| 50 |
|
| 51 |
+
# === 5. Buat DataFrame ===
|
| 52 |
+
df = pd.DataFrame(data)
|
| 53 |
+
|
| 54 |
except WebDriverException as e:
|
| 55 |
return page_title
|
| 56 |
finally:
|
| 57 |
if wd:
|
| 58 |
wd.quit()
|
| 59 |
|
| 60 |
+
return html , df
|