以前からnetkeibaさんの「俺プロ」の人のスコアリングをしながら予想をやっていたのですがそろそろ即patで自動で購入するところまで作ってみました。
作り方的には以下のようにつくりました。
import csv
import datetime
import itertools
import os
import re
import sys
from time import sleep
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.alert import Alert
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from webdriver_manager.chrome import ChromeDriverManager# セッションを起動する
options = Options()
options.headless = True
options.add_experimental_option(‘excludeSwitches’, [‘enable-logging’])
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)# レース情報ページにアクセスする
yoso_id = sys.argv[1]
url = f”https://orepro.netkeiba.com/mydata/yoso_detail.html?id={yoso_id}”
driver.get(url)# 購入情報テーブルの要素を取得する
table_element = driver.find_element(By.CSS_SELECTOR, ‘#capture > section.YosoDetailArea01.YosoDetailArea01_mydata > div.YosoDetailTableWrap’)# 購入情報を格納するリストを初期化する
bidder_list = []# 購入情報テーブルの各要素を処理する
for element in table_element.get_attribute(‘innerHTML’).split():# 購入者の名前を取得する
bidder_name_match = re.search(r”<th>(.*?)<span”, element)
if bidder_name_match:
bidder_name = bidder_name_match.group(1)
bidder_info = [bidder_name]# 購入方式を取得する
bidding_system_match = re.search(r’class=”BakenSystemTxt”>(.+?)</span></th>’, element)
if bidding_system_match:
bidding_system = bidding_system_match.group(1)
bidder_info.append(bidding_system)# 購入金額を取得する
price_matches = re.findall(r'<span>(\d+)</span>’, element)
if price_matches:
prices = [int(price) for price in price_matches]
bidder_info += prices# 単勝・複勝・枠連・馬連・ワイド・馬単・3連複・3連単の購入金額を取得する
win_match = re.search(r'<strong>([\d,]+)円</strong>’, element)
place_match = re.search(r'<strong>各(\d+)円</strong>’, element)
quinella_match = re.search(r'<strong>各([\d,]+)円</strong>’, element)if win_match:
win_price = int(win_match.group(1).replace(“,”, “”))
bidder_info.insert(0, win_price)
bidder_list.append(bidder_info)if place_match:
place_price = int(place_match.group(1))
bidder_info.insert(0, place_price)
bidder_list.append(bidder_info)if quinella_match:
quinella_price = int(quinella_match.group(1).replace(“,”, “”))
bidder_info.insert(0, quinella_price)
bidder_list.append(bidder_info)print(bidder_list)