-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDay1.py
43 lines (35 loc) · 1.31 KB
/
Day1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from selenium import webdriver
import pandas as pd
website = "https://www.adamchoi.co.uk/overs/detailed"
path = r"C:/SeleniumDrivers/chromedriver.exe"
driver = webdriver.Chrome(path)
driver.get(website)
#find the button
all_matches_button = driver.find_element_by_css_selector('label[analytics-event="All matches"]')
#click on it
all_matches_button.click()
#select tables
matches = driver.find_elements_by_css_selector("table.table-bordered")
###Select the 1st table
#Select the 1st column
date = matches[0].find_elements_by_css_selector("tr td:nth-of-type(1)")
#Select the 2nd column
team_1 = matches[0].find_elements_by_css_selector("tr td:nth-of-type(2)")
#Select the 3rd column
goal = matches[0].find_elements_by_css_selector("tr td:nth-of-type(3)")
#Select the 4th column
team_2 = matches[0].find_elements_by_css_selector("tr td:nth-of-type(4)")
l_home, l_date, l_goal, l_away = [], [], [], []
#Add each column to a list
for i in range(len(date)):
l_date += [date[i].text]
l_home += [team_1[i].text]
l_goal += [str(goal[i].text)+"'"]
l_away += [team_2[i].text]
#Once we finish scraping we close the browser
driver.quit()
#Create a dict to save the date as csv using pandas
data = {"date":l_date,"home":l_home,"Goals":l_goal,"away":l_away}
df = pd.DataFrame(data)
df.to_csv("matches.csv", index=False)
print(df.head(3))