0% found this document useful (0 votes)
8 views4 pages

V-League 2024 Data Scraping Script

The document contains a Python script that uses Selenium to scrape data from a webpage related to the V-League 2024. It collects various statistics such as team positions, wins, draws, losses, and points, and then stores this data in a Pandas DataFrame. Finally, the DataFrame is exported to a CSV file named '20232024.csv'.

Uploaded by

hoa58582005
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

V-League 2024 Data Scraping Script

The document contains a Python script that uses Selenium to scrape data from a webpage related to the V-League 2024. It collects various statistics such as team positions, wins, draws, losses, and points, and then stores this data in a Pandas DataFrame. Finally, the DataFrame is exported to a CSV file named '20232024.csv'.

Uploaded by

hoa58582005
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

python

May 31, 2024

1 2023/2024
[1]: from selenium import webdriver
from [Link] import By
from [Link] import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
from unidecode import unidecode
import time
def convert_to_unsigned_vietnamese(text_list):
return [unidecode(text) for text in text_list]

# Thiết lập trình duyệt và khởi động webdriver


driver = [Link](service=ChromeService(ChromeDriverManager().
↪install()))

# Truy cập vào trang web


url = "[Link]
↪fbclid=IwZXh0bgNhZW0CMTAAAR3mtoXg7ktZgKAePwfoOtZ6ilEJyq1glczZhzgyI5S5KVk2UDCk-yLZlUQ_aem_AXQ

[Link](url)

[Link](5)

vitri = []
name = []
tran = []
Thang = []
Hoa = []
Thua = []
B = []
BT_BB = []
HS = []
btsk = []
Td = []
Diem = []

# Lặp qua các hàng trong bảng và lấy dữ liệu


for i in range(1, 15):

1
element = driver.find_element([Link], f"/html/body/div[6]/div[2]/div/
↪div[2]/div/div/article/div[2]/div/div/div[4]/div[3]/div/div/div/div[1]/table/
↪tbody/tr[{i}]/td[1]")

[Link]([Link])
element = driver.find_element([Link], f"/html/body/div[6]/div[2]/div/
↪div[2]/div/div/article/div[2]/div/div/div[4]/div[3]/div/div/div/div[1]/table/

↪tbody/tr[{i}]/td[2]")

[Link]([Link])
element = driver.find_element([Link], f"/html/body/div[6]/div[2]/div/
↪div[2]/div/div/article/div[2]/div/div/div[4]/div[3]/div/div/div/div[1]/table/

↪tbody/tr[{i}]/td[3]")

[Link]([Link])
element = driver.find_element([Link], f"/html/body/div[6]/div[2]/div/
↪div[2]/div/div/article/div[2]/div/div/div[4]/div[3]/div/div/div/div[1]/table/

↪tbody/tr[{i}]/td[4]")

[Link]([Link])
element = driver.find_element([Link], f"/html/body/div[6]/div[2]/div/
↪div[2]/div/div/article/div[2]/div/div/div[4]/div[3]/div/div/div/div[1]/table/

↪tbody/tr[{i}]/td[5]")

[Link]([Link])
element = driver.find_element([Link], f"/html/body/div[6]/div[2]/div/
↪div[2]/div/div/article/div[2]/div/div/div[4]/div[3]/div/div/div/div[1]/table/

↪tbody/tr[{i}]/td[6]")

[Link]([Link])
element = driver.find_element([Link], f"/html/body/div[6]/div[2]/div/
↪div[2]/div/div/article/div[2]/div/div/div[4]/div[3]/div/div/div/div[1]/table/

↪tbody/tr[{i}]/td[7]")

[Link]([Link])
element = driver.find_element([Link], f"/html/body/div[6]/div[2]/div/
↪div[2]/div/div/article/div[2]/div/div/div[4]/div[3]/div/div/div/div[1]/table/

↪tbody/tr[{i}]/td[8]")

BT_BB.append([Link])
element = driver.find_element([Link], f"/html/body/div[6]/div[2]/div/
↪div[2]/div/div/article/div[2]/div/div/div[4]/div[3]/div/div/div/div[1]/table/

↪tbody/tr[{i}]/td[9]")

[Link]([Link])
element = driver.find_element([Link], f"/html/body/div[6]/div[2]/div/
↪div[2]/div/div/article/div[2]/div/div/div[4]/div[3]/div/div/div/div[1]/table/

↪tbody/tr[{i}]/td[10]")

[Link]([Link])
element = driver.find_element([Link], f"/html/body/div[6]/div[2]/div/
↪div[2]/div/div/article/div[2]/div/div/div[4]/div[3]/div/div/div/div[1]/table/

↪tbody/tr[{i}]/td[11]")

[Link]([Link])

2
element = driver.find_element([Link], f"/html/body/div[6]/div[2]/div/
↪div[2]/div/div/article/div[2]/div/div/div[4]/div[3]/div/div/div/div[1]/table/
↪tbody/tr[{i}]/td[12]")

[Link]([Link])
#Chuyển Tiếng Việt có dấu thành không dấu
Tenclb = convert_to_unsigned_vietnamese(name)
# In ra dữ liệu
print(vitri)
print(Tenclb)
print(tran)
print(Thang)
print(Hoa)
print(Thua)
print(B)
print(BT_BB)
print(HS)
print(btsk)
print(Td)
print(Diem)

# Đóng trình duyệt


[Link]()

['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14']
['Thep Xanh Nam Dinh', 'MerryLand Quy Nhon Binh Dinh', 'Ha Noi', 'Becamex Binh
Duong', 'Hai Phong', 'Cong An Ha Noi', 'The Cong - Viettel', 'TP Ho Chi Minh',
'Dong A Thanh Hoa', 'Quang Nam', 'Song Lam Nghe An', 'LPBank Hoang Anh Gia Lai',
'Hong Linh Ha Tinh', 'Khanh Hoa']
['21', '21', '21', '21', '21', '21', '21', '21', '21', '21', '21', '21', '21',
'21']
['13', '9', '10', '10', '8', '9', '8', '8', '8', '6', '6', '6', '6', '2']
['3', '7', '3', '3', '8', '4', '6', '5', '5', '8', '7', '7', '6', '4']
['5', '5', '8', '8', '5', '8', '7', '8', '8', '7', '8', '8', '9', '15']
['49 - 34', '34 - 24', '32 - 27', '27 - 24', '36 - 28', '32 - 27', '21 - 24',
'25 - 24', '31 - 32', '24 - 27', '21 - 25', '18 - 27', '22 - 29', '15 - 35']
['15', '10', '5', '3', '8', '5', '-3', '1', '-1', '-3', '-4', '-9', '-7', '-20']
['26', '16', '15', '10', '18', '12', '10', '7', '11', '12', '9', '7', '9', '8']
['34', '42', '32', '30', '32', '54', '47', '44', '53', '37', '38', '42', '45',
'33']
['2', '0', '2', '0', '1', '4', '2', '2', '5', '2', '2', '1', '2', '0']
['42', '34', '33', '33', '32', '31', '30', '29', '29', '26', '25', '25', '24',
'10']

[2]: import pandas as pd

3
df = pd.
↪DataFrame(list(zip(vitri,Tenclb,tran,Thang,Hoa,Thua,B,BT_BB,HS,btsk,Td,Diem)),columns␣

↪=["Vị trí",'Đội bóng','Trận','Thắng','Hòa','Thua','BT_BB','Hiệu␣

↪số','BTSK',"Thẻ Vàng",'Thẻ đỏ','Điểm'])

df

[2]: Vị trí Đội bóng Trận Thắng Hòa Thua BT_BB Hiệu số \
0 1 Thep Xanh Nam Dinh 21 13 3 5 49 - 34 15
1 2 MerryLand Quy Nhon Binh Dinh 21 9 7 5 34 - 24 10
2 3 Ha Noi 21 10 3 8 32 - 27 5
3 4 Becamex Binh Duong 21 10 3 8 27 - 24 3
4 5 Hai Phong 21 8 8 5 36 - 28 8
5 6 Cong An Ha Noi 21 9 4 8 32 - 27 5
6 7 The Cong - Viettel 21 8 6 7 21 - 24 -3
7 8 TP Ho Chi Minh 21 8 5 8 25 - 24 1
8 9 Dong A Thanh Hoa 21 8 5 8 31 - 32 -1
9 10 Quang Nam 21 6 8 7 24 - 27 -3
10 11 Song Lam Nghe An 21 6 7 8 21 - 25 -4
11 12 LPBank Hoang Anh Gia Lai 21 6 7 8 18 - 27 -9
12 13 Hong Linh Ha Tinh 21 6 6 9 22 - 29 -7
13 14 Khanh Hoa 21 2 4 15 15 - 35 -20

BTSK Thẻ Vàng Thẻ đỏ Điểm


0 26 34 2 42
1 16 42 0 34
2 15 32 2 33
3 10 30 0 33
4 18 32 1 32
5 12 54 4 31
6 10 47 2 30
7 7 44 2 29
8 11 53 5 29
9 12 37 2 26
10 9 38 2 25
11 7 42 1 25
12 9 45 2 24
13 8 33 0 10

[3]: # xuất df ra csv


df.to_csv('[Link]',index=False)

You might also like