An Easy Guide to Hong Kong Horse Racing Programming (Chapter : Auto Bet)
(Please scroll down for English version)
依個年代,其實以統計學為基本,加上些少編程來”賭”馬已是
大勢所趨。小弟最近有些少時間,會不定時在這分享一下香港賽馬所會用到的編程教學,總結一下這幾年來的心得點滴。希望各位志同道合朋友交流交流,各有得益。
我把整個賭馬系統分為5個部分,今天先說說最容易的自動下注部分。有什麼想知道也可以告訴我,看看我有什麼可以分享。
這個系統我最常會用到的編程語言是PYTHON (我用的版本是3.5.2)。不會用的話也不怕,網上有很多教學,遲下我也可以做些懶人包,教一下基本的應用。
預期成果
- 自動登入
- 自動下注各個彩池
事前準備
- Selenium (用以直接操控瀏覽器)
打開CMD,然後輸入
pip install selenium
- 下載 chrome drive
https://chromedriver.storage.googleapis.com/index.html?path=87.0.4280.20/
流程
Step 1: 用Chrome打開馬會投注網頁,然用按F12開啟開發者工具。
Step 2: 按Control F尋找需要用到的HTML Tag備用。
Step 3: 編程打開Chrome Driver,然後等待要用到的部分LOAD完
Step 4: 輸入登入資料,然後按鍵
Step 5: 下注 (按下最後一步的確認按鈕就留給大家完成吧)
重點學習內容
- 用Chrome Selenium控制Browser。超有用,也可以用來做網路爬蟲 (WEB SCRAPER)
- Selenium的有用FUNCTIONS : ActionChains, WebdriverWait
- 等待網路回應時要用sleep令program不要走過頭
- 其實慢慢學,程式也是很容易的。至於賽馬贏錢,就要看你有多了解這個運動了~我地下次再講!
Using statistics and machine learning for horse race betting has been an uprising trend these years. With some spare time, I would like to share some of my thoughts and findings on HK Jockey Club horse racing here. If you are interested, please feel free to exchange ideas here, I believe it would be a beneficial journey!
I have divided the horse racing system into 5 sections, today I would cover the easiest part — betting automation. In case you are interested in other topics, please feel free to let me know, I would see what I could share from there.
The most common programming language that I used is Python (my version is 3.5.2) No worries if you are newbie, there are a lot of guidance or source online, I could share some quick tips on basic application too.
EXPECTED RESULTS
- Automatic login
- Automatic betting on different pools
PREPARATION
- Selenium (Direct control of the browser)
Open CMD and type
pip install selenium
- Download chrome drive
https://chromedriver.storage.googleapis.com/index.html?path=87.0.4280.20/
STEPS
Step 1: Open HK Jockey Club betting website using Chrome, then open developer Tool by pressing F12
Step 2: Find the required HTML tag via Ctrl+F
Step 3: Open Chrome Driver using selenium, and wait until fully load
Step 4: Input the login information and press login button
Step 5: Betting (I would leave the last step — press the confirm button to you)
KEY TAKEAWAY
- Using Chrome Selenium to control Browser. Very useful technics, even for web scraper
- Some useful function in Selenium, e.g. ActionChains, WebdriverWait
- Sometimes it may takes time get response from the internet, make good use of “sleep” function to avoid out-sync
- Take it slow, actually program is pretty easy. As for win money via horse race betting, it depends on how much you understand the game. We will cover that next time!