from datetime import datetime, timedelta
from selenium import webdriver
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.keys import Keys
s = Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=s)
current_date = datetime.now()
data_list = []
for day in range(1, 501):
driver.get("https://www.thantai1.net/so-ket-qua")
try:
driver.get("https://www.thantai1.net/so-ket-qua")
date_input = driver.find_element(By.XPATH, '//*[@id="end"]')
date_input.clear()
date_string = date_input.send_keys("{}-{}-{}".format(current_date.day, current_date.month, current_date.year))
#
view_button = driver.find_element(By.XPATH, '//*[@id="skq"]/form/div[3]/div/button')
view_button.click()
except Exception as e:
print(f"Lỗi trong quá trình truy cập trang web cho ngày {date_string}: {str(e)}")
current_date -= timedelta(days=1)
driver.quit()