import pandas as pd from tinydb import TinyDB, Query from selenium import webdriver from time import sleep from tqdm.auto import tqdm from selenium.webdriver.common.by import By from selenium.webdriver.chrome.service import Service from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from datetime import date, timedelta # Tarih ayarlama bugun = date.today() + timedelta(1) jogos_do_dia = TinyDB(f'Jogos_do_Dia_FlashScore_{bugun}.json') # WebDriver ayarları options = webdriver.ChromeOptions() # options.add_argument('--headless') # Başsız modda çalıştırmak için bu satırı kullanabilirsiniz. s = Service('C:/mavi/chromedriver.exe') # Chromedriver yolunu güncelleyin driver = webdriver.Chrome(service=s, options=options) driver.maximize_window() # Sayfayı aç url = 'https://www.flashscore.co.uk/football/france/ligue-1/results/' driver.get(url) # Çerez kabul butonunu kapatma try: WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'button#onetrust-accept-btn-handler'))) driver.find_element(By.CSS_SELECTOR, 'button#onetrust-accept-btn-handler').click() except Exception as e: print("Çerezler zaten kapalı veya bulunamadı:", e) # Maçları bulma jogos = driver.find_elements(By.CSS_SELECTOR, 'div.event__match--twoLine') id_jogos = [i.get_attribute("id")[4:] for i in jogos] print(driver.title) for id_jogo in tqdm(id_jogos): procura_duplicado = Query() if jogos_do_dia.search(procura_duplicado.Id == id_jogo) == []: driver.get(f'https://www.flashscore.co.uk/match/{id_jogo}/#/match-summary/match-summary')
jogo = {} try: # Temel Bilgileri Alma jogo['Id'] = id_jogo country = driver.find_element(By.CSS_SELECTOR, 'span.tournamentHeader__country').text.split(':')[0] tarih = driver.find_element(By.CSS_SELECTOR, 'div.duelParticipant__startTime').text.split(' ')[0] jogo['TARİH'] = tarih.replace('/', '.') saat = driver.find_element(By.CSS_SELECTOR, 'div.duelParticipant__startTime').text.split(' ')[1] jogo['SAAT'] = saat league = driver.find_element(By.CSS_SELECTOR, 'span.tournamentHeader__country > a').text.split(' -')[0] jogo['LİG'] = f'{country} - {league}' ev_sahibi = driver.find_element(By.CSS_SELECTOR, 'div.duelParticipant__home .participant__participantName').text jogo['EV SAHİBİ'] = ev_sahibi deplasman = driver.find_element(By.CSS_SELECTOR, 'div.duelParticipant__away .participant__participantName').text jogo['DEPLASMAN'] = deplasman
# Maç Özetini Alma try: incidents_header = driver.find_elements(By.CSS_SELECTOR, 'div.smv__incidentsHeader.section__title') if len(incidents_header) >= 2: # Hem 1. Yarı hem de 2. Yarı bilgilerini al first_half = incidents_header[0].find_elements(By.TAG_NAME, 'div') second_half = incidents_header[1].find_elements(By.TAG_NAME, 'div')
jogo['İY SKOR'] = first_half[1].text.replace(' - ', '-') jogo['İKY SKOR'] = second_half[1].text.replace(' - ', '-') except Exception as e: print(f"Yarı skoru alınamadı: {e}") # Skor Alma skor = driver.find_element(By.CSS_SELECTOR, 'div.duelParticipant__score').text.replace('FINISHED', '').strip() jogo['MS SKOR'] = skor
# Maç Odds'larını Alma url_ml_full_time = f'https://www.flashscore.co.uk/match/{id_jogo}/#/odds-comparison/1x2-odds/full-time' driver.get(url_ml_full_time) sleep(1) if driver.current_url == url_ml_full_time: WebDriverWait(driver, 8).until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'div.ui-table'))) table_odds = driver.find_element(By.CSS_SELECTOR, 'div.ui-table') odds_elements = table_odds.find_elements(By.CSS_SELECTOR, 'a.oddsCell__odd') # Oranları alma for index, odds in enumerate(odds_elements): title_text = odds.get_attribute('title') if title_text: # title varsa if index == 0: jogo['MS1 A'] = title_text.split('»')[0].strip() # 1. Açılış oranı elif index == 1: jogo['MSX A'] = title_text.split('»')[0].strip() # 2. Açılış oranı elif index == 2: jogo['MS2 A'] = title_text.split('»')[0].strip() # 3. Açılış oranı else: # title yoksa if index == 0: jogo['MS1 A'] = odds.text.strip() # 1. Oran metni elif index == 1: jogo['MSX A'] = odds.text.strip() # 2. Oran metni elif index == 2: jogo['MS2 A'] = odds.text.strip() # 3. Oran metni # Ekstra Oran Bilgileri driver.get(url_ml_full_time) sleep(1) if driver.current_url == url_ml_full_time: WebDriverWait(driver, 8).until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'div.ui-table'))) table_odds = driver.find_element(By.CSS_SELECTOR, 'div.ui-table') linha_ml_ft = table_odds.find_element(By.CSS_SELECTOR, 'div.ui-table__row') jogo['MS1 K'] = format(float(linha_ml_ft.find_elements(By.CSS_SELECTOR, 'a.oddsCell__odd')[0].text.replace(',', '.')), '.2f') jogo['MSX K'] = format(float(linha_ml_ft.find_elements(By.CSS_SELECTOR, 'a.oddsCell__odd')[1].text.replace(',', '.')), '.2f') jogo['MS2 K'] = format(float(linha_ml_ft.find_elements(By.CSS_SELECTOR, 'a.oddsCell__odd')[2].text.replace(',', '.')), '.2f') # İlk Yarı Odds'larını Alma url_ml_1st_half = f'https://www.flashscore.co.uk/match/{id_jogo}/#/odds-comparison/1x2-odds/1st-half' driver.get(url_ml_1st_half) sleep(1) if driver.current_url == url_ml_1st_half: WebDriverWait(driver, 8).until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'div.ui-table'))) table_odds = driver.find_element(By.CSS_SELECTOR, 'div.ui-table') odds_elements = table_odds.find_elements(By.CSS_SELECTOR, 'a.oddsCell__odd') # Oranları alma for index, odds in enumerate(odds_elements): title_text = odds.get_attribute('title') if title_text: # title varsa if index == 0: jogo['İY1 A'] = title_text.split('»')[0].strip() # 1. Açılış oranı elif index == 1: jogo['İYX A'] = title_text.split('»')[0].strip() # 2. Açılış oranı elif index == 2: jogo['İY2 A'] = title_text.split('»')[0].strip() # 3. Açılış oranı else: # title yoksa if index == 0: jogo['İY1 A'] = odds.text.strip() # 1. Oran metni elif index == 1: jogo['İYX A'] = odds.text.strip() # 2. Oran metni elif index == 2: jogo['İY2 A'] = odds.text.strip() # 3. Oran metni # Ekstra Oran Bilgileri driver.get(url_ml_1st_half) sleep(1) if driver.current_url == url_ml_1st_half: WebDriverWait(driver, 8).until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'div.ui-table'))) table_odds = driver.find_element(By.CSS_SELECTOR, 'div.ui-table') linha_ml_1st_half = table_odds.find_element(By.CSS_SELECTOR, 'div.ui-table__row') jogo['İY1 K'] = format(float(linha_ml_1st_half.find_elements(By.CSS_SELECTOR, 'a.oddsCell__odd')[0].text.replace(',', '.')), '.2f') jogo['İYX K'] = format(float(linha_ml_1st_half.find_elements(By.CSS_SELECTOR, 'a.oddsCell__odd')[1].text.replace(',', '.')), '.2f') jogo['İY2 K'] = format(float(linha_ml_1st_half.find_elements(By.CSS_SELECTOR, 'a.oddsCell__odd')[2].text.replace(',', '.')), '.2f') # İkinci Yarı Odds'larını Alma url_ml_2nd_half = f'https://www.flashscore.co.uk/match/{id_jogo}/#/odds-comparison/1x2-odds/2nd-half' driver.get(url_ml_2nd_half) sleep(1) if driver.current_url == url_ml_2nd_half: WebDriverWait(driver, 8).until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'div.ui-table'))) table_odds = driver.find_element(By.CSS_SELECTOR, 'div.ui-table') odds_elements = table_odds.find_elements(By.CSS_SELECTOR, 'a.oddsCell__odd') # Oranları alma for index, odds in enumerate(odds_elements): title_text = odds.get_attribute('title') if title_text: # title varsa if index == 0: jogo['İKY1 A'] = title_text.split('»')[0].strip() # 1. Açılış oranı elif index == 1: jogo['İKYX A'] = title_text.split('»')[0].strip() # 2. Açılış oranı elif index == 2: jogo['İKY2 A'] = title_text.split('»')[0].strip() # 3. Açılış oranı else: # title yoksa if index == 0: jogo['İKY1 A'] = odds.text.strip() # 1. Oran metni elif index == 1: jogo['İKYX A'] = odds.text.strip() # 2. Oran metni elif index == 2: jogo['İKY2 A'] = odds.text.strip() # 3. Oran metni # Ekstra Oran Bilgileri driver.get(url_ml_2nd_half) sleep(1) if driver.current_url == url_ml_2nd_half: WebDriverWait(driver, 8).until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'div.ui-table'))) table_odds = driver.find_element(By.CSS_SELECTOR, 'div.ui-table') linha_ml_2nd_half = table_odds.find_element(By.CSS_SELECTOR, 'div.ui-table__row') jogo['İKY1 K'] = format(float(linha_ml_2nd_half.find_elements(By.CSS_SELECTOR, 'a.oddsCell__odd')[0].text.replace(',', '.')), '.2f') jogo['İKYX K'] = format(float(linha_ml_2nd_half.find_elements(By.CSS_SELECTOR, 'a.oddsCell__odd')[1].text.replace(',', '.')), '.2f') jogo['İKY2 K'] = format(float(linha_ml_2nd_half.find_elements(By.CSS_SELECTOR, 'a.oddsCell__odd')[2].text.replace(',', '.')), '.2f') selenium göre flashscore sitesinde bet365 oranları çekiyorum ama bir sıkıntı var bet365 oran açılmayan maçlar başka firmanın oran alıyor bunu çözmek için yardımcı olacak varmı? |
Bildirim