update,
This commit is contained in:
8
abc2022d/.gitignore
vendored
Normal file
8
abc2022d/.gitignore
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
**/~*
|
||||
**/*.zip
|
||||
**/*.7z
|
||||
**/Chromium
|
||||
**/_del
|
||||
**/*.tmp
|
||||
**/*.exe
|
||||
draft*
|
7
abc2022d/gitUpdate.bat
Normal file
7
abc2022d/gitUpdate.bat
Normal file
@@ -0,0 +1,7 @@
|
||||
git status .
|
||||
|
||||
@pause
|
||||
|
||||
git add .
|
||||
git commit -m"update abc2022d,"
|
||||
start git push
|
61
abc2022d/meta.md
Normal file
61
abc2022d/meta.md
Normal file
@@ -0,0 +1,61 @@
|
||||
---
|
||||
tags: "hkjc", "vba", "excel","selenium"
|
||||
---
|
||||
|
||||
# abc2022d
|
||||
|
||||
Tim206207@gmail.com
|
||||
|
||||
### balance history
|
||||
|
||||
5 layouts quote HKD2400
|
||||
|
||||
| --- | --- | --- |
|
||||
| --------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------ |
|
||||
| webpage 1 | 排位表 | https://racing.hkjc.com/racing/information/Chinese/racing/Racecard.aspx?RaceDate=2024/04/20&Racecourse=ST&RaceNo=1 |
|
||||
| webpage 2 | 個別馬匹資料頁面 | i.e. 魅力一心 https://racing.hkjc.com/racing/information/Chinese/Horse/Horse.aspx?HorseId=HK_2022_H195 |
|
||||
| (H195) |
|
||||
| webpage 3 | 賽馬結果 | https://racing.hkjc.com/racing/information/Chinese/racing/LocalResults.aspx |
|
||||
| webpage 4 | 分段時間 | https://racing.hkjc.com/racing/information/Chinese/Racing/DisplaySectionalTime.aspx?RaceDate=20/04/2024&RaceNo=1 |
|
||||
| webpage 5 | 操練 | https://racing.hkjc.com/racing/information/Chinese/Racing/LocalTrackwork.aspx?RaceDate=2024/04/20&Racecourse=ST&RaceNo=1 |
|
||||
|
||||
### chat history
|
||||
|
||||
Q:
|
||||
|
||||
1. 見到 vba 行 ge 途中, 佢拎個別馬 ge 資料係馬會 ge 英文版面
|
||||
2. 見到賽果個邊 columns, "HKJC not ready" , 21/4 賽果已出
|
||||
3. 到實際用 ge 時間應該有個制比我揀日期, 可以 generate 返之前 d 賽果?
|
||||
|
||||
A:
|
||||
|
||||
1. VBA 本身 support 中文冇咁好,有 D 位要用英文對一對佢 i.e. Gallop -> 踱步
|
||||
但係到最後都係會用中文網頁內容嘅,只係比較果陣時會用英文
|
||||
|
||||
2. 如果咁的話,咁左手邊果 D 行 (藍+灰) 會同右手邊果 D 行 (黃+粉紅) 唔對/匹配
|
||||
i.e. 20/04/2024 沙田日馬跑左 10 場,但係黎緊 24/04/2024 跑馬地 得 9 場,會變左左手邊突左場出黎
|
||||
係咪想咁?
|
||||
|
||||
3. 呢個可以呀,比個格你入日期落去
|
||||
|
||||
Q:
|
||||
如果之後有問題都可以繼續揾你?
|
||||
如果馬會啲 field/ webpage link 轉左,
|
||||
揾你修改要額外比錢嗎
|
||||
|
||||
A:
|
||||
一般計,轉 field/link 的話你搵番我我可以幫手改
|
||||
|
||||
但係如果佢係成個版面轉左花款的話(成個版面個樣轉左),
|
||||
咁果個 update 就收番個 update 錢
|
||||
|
||||
### materials
|
||||
|
||||
#### 安裝 dotnetfx35 and selenium basic
|
||||
|
||||
ttps://youtu.be/3mTbo63exHE
|
||||
|
||||
#### 點用
|
||||
|
||||
ttps://filetransfer.io/data-package/gES49XH7#link
|
||||
https://youtu.be/Kft1vWFmDrE
|
BIN
abc2022d/task1/_ref/Template_Description.docx
Normal file
BIN
abc2022d/task1/_ref/Template_Description.docx
Normal file
Binary file not shown.
BIN
abc2022d/task1/_ref/Template_Header.xlsx
Normal file
BIN
abc2022d/task1/_ref/Template_Header.xlsx
Normal file
Binary file not shown.
1
abc2022d/task1/backup.bat
Normal file
1
abc2022d/task1/backup.bat
Normal file
@@ -0,0 +1 @@
|
||||
node ./backup.js
|
63
abc2022d/task1/backup.js
Normal file
63
abc2022d/task1/backup.js
Normal file
@@ -0,0 +1,63 @@
|
||||
const execSync = require("child_process").execSync;
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
// Function to get all subdirectories of a given directory
|
||||
function getDirectories(srcPath, excludeDirs) {
|
||||
return fs
|
||||
.readdirSync(srcPath)
|
||||
.filter(
|
||||
(file) =>
|
||||
!excludeDirs.includes(file) &&
|
||||
fs.lstatSync(path.join(srcPath, file)).isDirectory()
|
||||
)
|
||||
.map((name) => path.join(srcPath, name));
|
||||
}
|
||||
|
||||
// Get current working directory
|
||||
const cwd = process.cwd();
|
||||
|
||||
// Path to app-head directory
|
||||
const appHeadDir = path.join(cwd, "src");
|
||||
|
||||
// Check if app-head exists
|
||||
if (!fs.existsSync(appHeadDir)) {
|
||||
console.error(`Error: ${appHeadDir} does not exist.`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Execute reset.bat scripts
|
||||
try {
|
||||
// execSync(`cmd /c "cd ${appHeadDir} && scripts\\reset.bat"`, { stdio: 'inherit' });
|
||||
} catch (err) {
|
||||
console.error(`Error executing reset.bat script: ${err.message}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Define excluded directories
|
||||
const excludedDirs = [".next", "node_modules", ".git", "Chromium"];
|
||||
|
||||
// Copy app-head directory and its contents to a new directory with an increasing number suffix
|
||||
let maxNum = 0;
|
||||
const directories = getDirectories(cwd, excludedDirs);
|
||||
for (const dir of directories) {
|
||||
const match = dir.match(/^.+draft(\d+)$/);
|
||||
if (match) {
|
||||
const num = parseInt(match[1], 10);
|
||||
if (num > maxNum) {
|
||||
maxNum = num;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var zerofilled = ("0000" + (maxNum + 1)).slice(-4);
|
||||
const targetDir = path.join(cwd, `draft${zerofilled}`);
|
||||
fs.mkdirSync(targetDir);
|
||||
|
||||
// Copy app-head directory and its contents to targetDir, excluding specified directories
|
||||
fs.cpSync(appHeadDir, targetDir, {
|
||||
filter: (src) => !excludedDirs.includes(path.basename(src)),
|
||||
recursive: true,
|
||||
});
|
||||
|
||||
console.log(`Successfully copied ${appHeadDir} to ${targetDir}.`);
|
2696
abc2022d/task1/hkjc_stub/LocalTrackwork_aspx.html
Normal file
2696
abc2022d/task1/hkjc_stub/LocalTrackwork_aspx.html
Normal file
File diff suppressed because it is too large
Load Diff
11196
abc2022d/task1/hkjc_stub/TrackworkResult_aspx.html
Normal file
11196
abc2022d/task1/hkjc_stub/TrackworkResult_aspx.html
Normal file
File diff suppressed because it is too large
Load Diff
2232
abc2022d/task1/hkjc_stub/racecard_aspx.html
Normal file
2232
abc2022d/task1/hkjc_stub/racecard_aspx.html
Normal file
File diff suppressed because it is too large
Load Diff
4477
abc2022d/task1/hkjc_stub/test/corse.html
Normal file
4477
abc2022d/task1/hkjc_stub/test/corse.html
Normal file
File diff suppressed because it is too large
Load Diff
BIN
abc2022d/task1/hkjc_stub/test/screencapture-racing-hkjc-racing-information-English-Racing-Racecard-aspx-2024-05-09-01_02_27.png
(Stored with Git LFS)
Normal file
BIN
abc2022d/task1/hkjc_stub/test/screencapture-racing-hkjc-racing-information-English-Racing-Racecard-aspx-2024-05-09-01_02_27.png
(Stored with Git LFS)
Normal file
Binary file not shown.
5
abc2022d/task1/src/dev.bat
Normal file
5
abc2022d/task1/src/dev.bat
Normal file
@@ -0,0 +1,5 @@
|
||||
@REM start excel by yourself
|
||||
|
||||
@REM ./test.xlsm
|
||||
|
||||
xlwings vba edit --file ./main.xlsm
|
BIN
abc2022d/task1/src/main.xlsm
Normal file
BIN
abc2022d/task1/src/main.xlsm
Normal file
Binary file not shown.
BIN
abc2022d/task1/src/main_ticket1.xlsm
Normal file
BIN
abc2022d/task1/src/main_ticket1.xlsm
Normal file
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 65 KiB |
75
abc2022d/task1/ticket0001/Common.bas
Normal file
75
abc2022d/task1/ticket0001/Common.bas
Normal file
@@ -0,0 +1,75 @@
|
||||
Attribute VB_Name = "Common"
|
||||
|
||||
Option Explicit
|
||||
|
||||
Global CURRENT_DIR As String
|
||||
|
||||
Function getDateFrRaceCardLink(ByVal in_str As String)
|
||||
' https://racing.hkjc.com/racing/information/English/Racing/Racecard.aspx?RaceDate=2024/04/24&Racecourse=HV&RaceNo=2
|
||||
Dim s_date, s_loc, s_race_num As String
|
||||
s_date = Split(Split(in_str, "=")(1), "&")(0)
|
||||
s_loc = Split(Split(in_str, "=")(2), "&")(0)
|
||||
s_race_num = Split(in_str, "=")(3)
|
||||
|
||||
getDateFrRaceCardLink = Array(s_date, s_loc, s_race_num)
|
||||
End Function
|
||||
|
||||
Function readCell(cell_address As String)
|
||||
Dim temp As String
|
||||
temp = Worksheets("Sheet1").Range(cell_address).value
|
||||
readCell = temp
|
||||
End Function
|
||||
|
||||
Function writeCell(cell_address As String, content As String)
|
||||
'write cell according to cell_address and content
|
||||
Worksheets("Sheet1").Range(cell_address).value = content
|
||||
|
||||
writeCell = content
|
||||
End Function
|
||||
|
||||
|
||||
Function ResetSheet()
|
||||
Worksheets("Sheet1").Range("A3:AC200").ClearContents
|
||||
End Function
|
||||
|
||||
|
||||
Function TidySheet()
|
||||
Worksheets("Sheet1").Range("OK1:OK200").ClearContents
|
||||
|
||||
'widen column width
|
||||
Worksheets("Sheet1").Range("A2:DF200").Columns.AutoFit
|
||||
|
||||
' align text to center
|
||||
Worksheets("Sheet1").Range("A2:DF200").HorizontalAlignment = xlCenter
|
||||
|
||||
End Function
|
||||
|
||||
|
||||
Function ParseDDMMYYYY(input_string As String)
|
||||
Dim s_day As String
|
||||
Dim s_month As String
|
||||
Dim s_year As String
|
||||
|
||||
s_day = Split(input_string, "/")(0)
|
||||
s_month = Split(input_string, "/")(1)
|
||||
s_year = Split(input_string, "/")(2)
|
||||
|
||||
ParseDDMMYYYY = DateSerial(CInt(s_year), CInt(s_month), CInt(s_day))
|
||||
End Function
|
||||
|
||||
Sub DisableScreenUpdate
|
||||
Application.ScreenUpdating = False 'disable screen updating
|
||||
Application.Calculation = xlCalculationManual 'disable automatic calculation
|
||||
Application.EnableEvents = False 'disable event handling
|
||||
Application.DisplayAlerts = False 'disable alerts
|
||||
|
||||
end sub
|
||||
|
||||
|
||||
sub ResumeScreenUpdate
|
||||
Application.ScreenUpdating = True 'enable screen updating
|
||||
Application.Calculation = xlCalculationAutomatic 'enable automatic calculation
|
||||
Application.EnableEvents = True 'enable event handling
|
||||
Application.DisplayAlerts = True 'enable alerts
|
||||
|
||||
end sub
|
163
abc2022d/task1/ticket0001/DisplaySectionalTime_aspx.bas
Normal file
163
abc2022d/task1/ticket0001/DisplaySectionalTime_aspx.bas
Normal file
@@ -0,0 +1,163 @@
|
||||
Attribute VB_Name = "DisplaySectionalTime_aspx"
|
||||
|
||||
Option Explicit
|
||||
|
||||
|
||||
Public Function ScrapeDisplaySectionalTime(driver As WebDriver, ByVal race_date As String, race_num As String, row_offset As Integer, ByVal horse_count As Integer)
|
||||
Dim COL_IDX_HORSE_NO As Integer
|
||||
Dim COL_IDX_LAST_6_RUNS As Integer
|
||||
Dim COL_IDX_COLOUR As Integer
|
||||
Dim COL_IDX_HORSE As Integer
|
||||
Dim COL_IDX_BRAND_NO As Integer
|
||||
Dim COL_IDX_WT As Integer
|
||||
Dim COL_IDX_JOCKEY As Integer
|
||||
Dim COL_IDX_OVER_WT As Integer
|
||||
Dim COL_IDX_DRAW As Integer
|
||||
Dim COL_IDX_TRAINER As Integer
|
||||
Dim COL_IDX_RTG As Integer
|
||||
Dim COL_IDX_RTG_PLUS_MINUS As Integer
|
||||
Dim COL_IDX_HORSE_WT_DECLARATION As Integer
|
||||
Dim COL_IDX_WT_PLUS_MINUS_VS_DECLARATION As Integer
|
||||
Dim COL_IDX_BEST_TIME As Integer
|
||||
Dim COL_IDX_AGE As Integer
|
||||
Dim COL_IDX_WFA As Integer
|
||||
Dim COL_IDX_SEX As Integer
|
||||
Dim COL_IDX_SEASON_STAKES As Integer
|
||||
Dim COL_IDX_PRIORITY As Integer
|
||||
Dim COL_IDX_DAYS_SINCE_LAST_RUN As Integer
|
||||
Dim COL_IDX_GEAR As Integer
|
||||
Dim COL_IDX_OWNER As Integer
|
||||
Dim COL_IDX_SIRE As Integer
|
||||
Dim COL_IDX_DAM As Integer
|
||||
Dim COL_IDX_IMPORT_CAT As Integer
|
||||
|
||||
Dim script_content, script_result As String
|
||||
|
||||
Dim i, j As Integer
|
||||
|
||||
|
||||
On Error GoTo ErrorHandler
|
||||
|
||||
' Navigate to a website.
|
||||
Dim s_year, s_month, s_date, temp_new_date As String
|
||||
s_year = Split(race_date, "/")(0)
|
||||
s_month = Split(race_date, "/")(1)
|
||||
s_date = Split(race_date, "/")(2)
|
||||
temp_new_date = s_date & "/" & s_month & "/" & s_year
|
||||
Dim s_race_date As String
|
||||
s_race_date = Format(temp_new_date, "DD/MM/YYYY")
|
||||
|
||||
driver.Get "https://racing.hkjc.com/racing/information/chinese/Racing/DisplaySectionalTime.aspx?RaceDate=" & s_race_date & "&RaceNo=" & race_num
|
||||
|
||||
|
||||
Dim startCell As Range
|
||||
Set startCell = Worksheets("Sheet1").Range("A3")
|
||||
|
||||
|
||||
|
||||
' test if match result table found
|
||||
Dim table_count, table_count_result As String
|
||||
table_count_result = driver.ExecuteScript("{ return document?.querySelectorAll('.Race').length }")
|
||||
table_count = CInt(table_count_result)
|
||||
|
||||
|
||||
If (table_count > 0) Then
|
||||
|
||||
|
||||
|
||||
Dim hourse_table As Variant
|
||||
script_content = "{" & _
|
||||
" list_e = [];" & _
|
||||
" document" & _
|
||||
" .querySelector('table.race_table')" & _
|
||||
" .querySelectorAll('tr')" & _
|
||||
" .forEach((e_tr, idx) => {" & _
|
||||
" if (idx > 2) {" & _
|
||||
" list_td = [];" & _
|
||||
" temp = e_tr.querySelectorAll('td');" & _
|
||||
" list_td.push(temp[2].textContent.replace(/[\(\)]/g,'').split(/\s/g)[1]);" & _
|
||||
" list_td.push(temp[3]?.querySelectorAll('p')[1]?.textContent.replace(/\n/g, '')?.split(/\s+/g)[0] || '-');" & _
|
||||
" list_td.push(temp[4]?.querySelectorAll('p')[1]?.textContent.replace(/\n/g, '')?.split(/\s+/g)[0] || '-');" & _
|
||||
" list_td.push(temp[5]?.querySelectorAll('p')[1]?.textContent.replace(/\n/g, '')?.split(/\s+/g)[0] || '-');" & _
|
||||
" list_td.push(temp[6]?.querySelectorAll('p')[1]?.textContent.replace(/\n/g, '')?.split(/\s+/g)[0] || '-');" & _
|
||||
" list_td.push(temp[7]?.querySelectorAll('p')[1]?.textContent.replace(/\n/g, '')?.split(/\s+/g)[0] || '-');" & _
|
||||
" list_td.push(temp[8]?.querySelectorAll('p')[1]?.textContent.replace(/\n/g, '')?.split(/\s+/g)[0] || '-');" & _
|
||||
" list_td.push(temp[9]?.textContent);" & _
|
||||
" list_e.push(list_td.join(','));" & _
|
||||
" }" & _
|
||||
" });" & _
|
||||
" return list_e.join('|||'); " & _
|
||||
"}"
|
||||
script_result = driver.ExecuteScript(script_content)
|
||||
hourse_table = Split(script_result, "|||")
|
||||
|
||||
'Country of origin
|
||||
' document.querySelector('table.race_table').querySelectorAll('tr')[2+1].querySelectorAll('td')[0-9]
|
||||
For i = LBound(hourse_table) To UBound(hourse_table)
|
||||
For j = LBound(hourse_table) To UBound(hourse_table)
|
||||
Dim temp As Variant
|
||||
temp = Split(hourse_table(j), ",")
|
||||
Dim horse_id As String
|
||||
|
||||
|
||||
If (InStr(startCell.Offset(row_offset + i, 37).value, temp(0)) > 0) Then
|
||||
startCell.Offset(row_offset + i, 51 + 0).value = temp(1)
|
||||
startCell.Offset(row_offset + i, 51 + 1).value = temp(2)
|
||||
startCell.Offset(row_offset + i, 51 + 2).value = temp(3)
|
||||
startCell.Offset(row_offset + i, 51 + 3).value = temp(4)
|
||||
startCell.Offset(row_offset + i, 51 + 4).value = temp(5)
|
||||
startCell.Offset(row_offset + i, 51 + 5).value = temp(6)
|
||||
startCell.Offset(row_offset + i, 51 + 6).value = "'" & temp(7)
|
||||
End If
|
||||
Next j
|
||||
Next i
|
||||
|
||||
|
||||
Else
|
||||
For j = 0 To horse_count - 1
|
||||
' table not ready yet
|
||||
startCell.Offset(row_offset + j, 30).value = "HKJC table not ready"
|
||||
Next j
|
||||
|
||||
End If
|
||||
|
||||
GoTo Done
|
||||
|
||||
ErrorHandler:
|
||||
MsgBox "hello error ?"
|
||||
MsgBox "Error: " & Err.Description
|
||||
|
||||
Done:
|
||||
Debug.Print "hello done"
|
||||
|
||||
|
||||
End Function
|
||||
|
||||
|
||||
|
||||
' write cell
|
||||
Sub writeCell(cell_addres As String, value As String)
|
||||
|
||||
End Sub
|
||||
|
||||
|
||||
Private Sub Take_ScreenShot_Desktop()
|
||||
Dim utils As New utils
|
||||
Dim driver As New ChromeDriver
|
||||
driver.Get "https://en.wikipedia.org/wiki/Main_Page"
|
||||
|
||||
Dim img As Object
|
||||
|
||||
'take a screenshot of the desktop
|
||||
Set img = utils.TakeScreenshot()
|
||||
|
||||
'save the image in the folder of the workbook
|
||||
img.SaveAs ThisWorkbook.Path & "\sc-desktop.png"
|
||||
|
||||
driver.Quit
|
||||
End Sub
|
||||
|
||||
|
||||
|
||||
|
||||
|
5
abc2022d/task1/ticket0001/Helloworld.bas
Normal file
5
abc2022d/task1/ticket0001/Helloworld.bas
Normal file
@@ -0,0 +1,5 @@
|
||||
Attribute VB_Name = "Helloworld"
|
||||
Sub TestHelloworld()
|
||||
|
||||
|
||||
End Sub
|
87
abc2022d/task1/ticket0001/Horse_aspx.bas
Normal file
87
abc2022d/task1/ticket0001/Horse_aspx.bas
Normal file
@@ -0,0 +1,87 @@
|
||||
Attribute VB_Name = "Horse_aspx"
|
||||
|
||||
Option Explicit
|
||||
|
||||
|
||||
Public Function ScrapeHorse(driver As WebDriver, horse_id As String, row_offset As String)
|
||||
Dim COL_IDX_HORSE_NO As Integer
|
||||
Dim COL_IDX_LAST_6_RUNS As Integer
|
||||
Dim COL_IDX_COLOUR As Integer
|
||||
Dim COL_IDX_HORSE As Integer
|
||||
Dim COL_IDX_BRAND_NO As Integer
|
||||
Dim COL_IDX_WT As Integer
|
||||
Dim COL_IDX_JOCKEY As Integer
|
||||
Dim COL_IDX_OVER_WT As Integer
|
||||
Dim COL_IDX_DRAW As Integer
|
||||
Dim COL_IDX_TRAINER As Integer
|
||||
Dim COL_IDX_RTG As Integer
|
||||
Dim COL_IDX_RTG_PLUS_MINUS As Integer
|
||||
Dim COL_IDX_HORSE_WT_DECLARATION As Integer
|
||||
Dim COL_IDX_WT_PLUS_MINUS_VS_DECLARATION As Integer
|
||||
Dim COL_IDX_BEST_TIME As Integer
|
||||
Dim COL_IDX_AGE As Integer
|
||||
Dim COL_IDX_WFA As Integer
|
||||
Dim COL_IDX_SEX As Integer
|
||||
Dim COL_IDX_SEASON_STAKES As Integer
|
||||
Dim COL_IDX_PRIORITY As Integer
|
||||
Dim COL_IDX_DAYS_SINCE_LAST_RUN As Integer
|
||||
Dim COL_IDX_GEAR As Integer
|
||||
Dim COL_IDX_OWNER As Integer
|
||||
Dim COL_IDX_SIRE As Integer
|
||||
Dim COL_IDX_DAM As Integer
|
||||
Dim COL_IDX_IMPORT_CAT As Integer
|
||||
|
||||
Dim script_content As String
|
||||
|
||||
' ' Create a new instance of the WebDriver.
|
||||
' Dim driver As New WebDriver
|
||||
|
||||
' ' Set the path to the WebDriver executable.
|
||||
' driver.SetBinary "C:\Users\logic\AppData\Local\Chromium\Application\chrome.exe"
|
||||
|
||||
' ' Start Chrome.
|
||||
' driver.Start "chrome"
|
||||
|
||||
' Navigate to a website.
|
||||
driver.Get "https://racing.hkjc.com/racing/information/Chinese/Horse/Horse.aspx?HorseId=" & horse_id
|
||||
|
||||
' document.querySelectorAll('#racecardlist tbody tr')[2].textContent
|
||||
Dim i, j As Integer
|
||||
|
||||
|
||||
Dim startCell As Range
|
||||
Set startCell = Worksheets("Sheet1").Range("A3")
|
||||
|
||||
|
||||
'Country of origin
|
||||
' document.querySelector('table.horseProfile').querySelectorAll('td')[6].querySelectorAll('td')[2]
|
||||
script_content = "{ return document.querySelector('table.horseProfile').querySelectorAll('td')[6].querySelectorAll('td')[2].textContent.trim().split('/')[0].trim() }"
|
||||
startCell.Offset(row_offset, 28).value = driver.ExecuteScript(script_content)
|
||||
|
||||
'import type
|
||||
' document.querySelector('table.horseProfile').querySelectorAll('td')[6].querySelectorAll('td')[8]
|
||||
script_content = "{ return document.querySelector('table.horseProfile').querySelectorAll('td')[6].querySelectorAll('td')[8].textContent.trim() }"
|
||||
|
||||
End Function
|
||||
|
||||
|
||||
|
||||
Private Sub Take_ScreenShot_Desktop()
|
||||
Dim utils As New utils
|
||||
Dim driver As New ChromeDriver
|
||||
driver.Get "https://en.wikipedia.org/wiki/Main_Page"
|
||||
|
||||
Dim img As Object
|
||||
|
||||
'take a screenshot of the desktop
|
||||
Set img = utils.TakeScreenshot()
|
||||
|
||||
'save the image in the folder of the workbook
|
||||
img.SaveAs ThisWorkbook.Path & "\sc-desktop.png"
|
||||
|
||||
driver.Quit
|
||||
End Sub
|
||||
|
||||
|
||||
|
||||
|
243
abc2022d/task1/ticket0001/LocalResults_aspx.bas
Normal file
243
abc2022d/task1/ticket0001/LocalResults_aspx.bas
Normal file
@@ -0,0 +1,243 @@
|
||||
Attribute VB_Name = "LocalResults_aspx"
|
||||
|
||||
Option Explicit
|
||||
|
||||
|
||||
Public Sub ScrapeLocalResults()
|
||||
Dim COL_IDX_HORSE_NO As Integer
|
||||
Dim COL_IDX_LAST_6_RUNS As Integer
|
||||
Dim COL_IDX_COLOUR As Integer
|
||||
Dim COL_IDX_HORSE As Integer
|
||||
Dim COL_IDX_BRAND_NO As Integer
|
||||
Dim COL_IDX_WT As Integer
|
||||
Dim COL_IDX_JOCKEY As Integer
|
||||
Dim COL_IDX_OVER_WT As Integer
|
||||
Dim COL_IDX_DRAW As Integer
|
||||
Dim COL_IDX_TRAINER As Integer
|
||||
Dim COL_IDX_RTG As Integer
|
||||
Dim COL_IDX_RTG_PLUS_MINUS As Integer
|
||||
Dim COL_IDX_HORSE_WT_DECLARATION As Integer
|
||||
Dim COL_IDX_WT_PLUS_MINUS_VS_DECLARATION As Integer
|
||||
Dim COL_IDX_BEST_TIME As Integer
|
||||
Dim COL_IDX_AGE As Integer
|
||||
Dim COL_IDX_WFA As Integer
|
||||
Dim COL_IDX_SEX As Integer
|
||||
Dim COL_IDX_SEASON_STAKES As Integer
|
||||
Dim COL_IDX_PRIORITY As Integer
|
||||
Dim COL_IDX_DAYS_SINCE_LAST_RUN As Integer
|
||||
Dim COL_IDX_GEAR As Integer
|
||||
Dim COL_IDX_OWNER As Integer
|
||||
Dim COL_IDX_SIRE As Integer
|
||||
Dim COL_IDX_DAM As Integer
|
||||
Dim COL_IDX_IMPORT_CAT As Integer
|
||||
|
||||
Dim not_used As Variant
|
||||
|
||||
On Error GoTo ErrorHandler
|
||||
ResetCell
|
||||
|
||||
Dim race_date As String
|
||||
Dim s_year, s_month, s_date, temp_new_date As String
|
||||
race_date = Common.readCell("AE1")
|
||||
|
||||
s_year = Split(race_date, "/")(0)
|
||||
s_month = Split(race_date, "/")(1)
|
||||
s_date = Split(race_date, "/")(2)
|
||||
temp_new_date = s_date & "/" & s_month & "/" & s_year
|
||||
|
||||
Dim s_race_date As String
|
||||
s_race_date = Format(temp_new_date, "DD/MM/YYYY")
|
||||
|
||||
|
||||
'ByVal race_date As String, race_num As String, row_offset As Integer, horse_count As Integer
|
||||
Dim row_offset As Integer
|
||||
row_offset = 0
|
||||
|
||||
' on error goto eh
|
||||
On Error GoTo ErrorHandler
|
||||
|
||||
' Create a new instance of the WebDriver.
|
||||
Dim driver As New WebDriver
|
||||
|
||||
' Set the path to the WebDriver executable.
|
||||
|
||||
Dim CURRENT_DIR As String
|
||||
CURRENT_DIR = ThisWorkbook.Path
|
||||
driver.SetBinary CURRENT_DIR & "\Chromium\Application\chrome.exe"
|
||||
driver.AddArgument "--disable-blink-features=AutomationControlled --blink-settings=imagesEnabled=false"
|
||||
|
||||
' Start Chrome.
|
||||
driver.Start "chrome"
|
||||
|
||||
|
||||
Dim By As New By
|
||||
' Navigate to a website.
|
||||
' https://racing.hkjc.com/racing/information/Chinese/Racing/LocalResults.aspx?RaceDate=2024/04/20&Racecourse=ST&RaceNo=1
|
||||
driver.Get "https://racing.hkjc.com/racing/information/Chinese/Racing/LocalResults.aspx?RaceDate=" & s_race_date & "&RaceNo=1"
|
||||
|
||||
' document.querySelectorAll('#racecardlist tbody tr')[2].textContent
|
||||
|
||||
Dim startCell As Range
|
||||
Set startCell = Worksheets("Sheet1").Range("A3")
|
||||
|
||||
Dim hourse_number As String
|
||||
Dim script_content, script_result As String
|
||||
Dim hourse_table As Variant
|
||||
|
||||
|
||||
' test if match result table found
|
||||
Dim table_count, table_count_result As String
|
||||
table_count_result = driver.ExecuteScript("{ return document.querySelectorAll('.performance').length }")
|
||||
table_count = CInt(table_count_result)
|
||||
|
||||
' find max race_num
|
||||
Dim max_race_num As Integer
|
||||
|
||||
script_content = "{" & _
|
||||
" let all_a = {};" & _
|
||||
" all_a = document.querySelectorAll('.top_races a');" & _
|
||||
" return all_a?.item(all_a?.length-2)?.href?.split('=')[3] || 0;" & _
|
||||
"}"
|
||||
|
||||
|
||||
max_race_num = CInt(driver.ExecuteScript(script_content))
|
||||
|
||||
Dim i, j, k, l As Integer
|
||||
|
||||
Dim current_row As Integer
|
||||
current_row = row_offset
|
||||
|
||||
|
||||
For l = 1 To max_race_num
|
||||
driver.Get "https://racing.hkjc.com/racing/information/Chinese/Racing/LocalResults.aspx?RaceDate=" & race_date & "&RaceNo=" & CStr(l)
|
||||
script_content = "{" & _
|
||||
"list_e = [];" & _
|
||||
"document" & _
|
||||
" .querySelector('.performance table')" & _
|
||||
" .querySelectorAll('tr')" & _
|
||||
" .forEach((e_tr, idx) => {" & _
|
||||
" if (idx > 0) {" & _
|
||||
" let temp = e_tr.querySelectorAll('td');" & _
|
||||
" let temp_l = [];" & _
|
||||
" temp.forEach(e => temp_l.push(e.textContent.trim()));" & _
|
||||
" list_e.push(" & _
|
||||
" [" & _
|
||||
" temp_l.join(',')," & _
|
||||
" temp[9].textContent.replace(/[\n| ]+/g, '_').slice(1,-1)," & _
|
||||
" ].join(',')" & _
|
||||
" );" & _
|
||||
" }" & _
|
||||
" });" & _
|
||||
"return list_e.join('|||')" & _
|
||||
"}"
|
||||
script_result = driver.ExecuteScript(script_content)
|
||||
hourse_table = Split(script_result, "|||")
|
||||
|
||||
Dim table_race_date, race_course, race_number, total_race_number, race_cource_desc As String
|
||||
table_race_date = driver.ExecuteScript("{ return document.querySelector('div.raceMeeting_select')?.querySelectorAll('p')[0]?.querySelectorAll('span')[0]?.textContent.split(/ +/g)[1] || '-'}")
|
||||
race_course = driver.ExecuteScript("{ return document.querySelector('div.raceMeeting_select')?.querySelectorAll('p')[0]?.querySelectorAll('span')[0]?.textContent.split(/ +/g)[3] || '-'}")
|
||||
race_number = driver.ExecuteScript("{ return document.querySelectorAll('div.race_tab td')[0]?.textContent?.split(/\s\(/g)[0] || '-'; }")
|
||||
total_race_number = driver.ExecuteScript("{ return document.querySelectorAll('div.race_tab td')[0]?.textContent?.split(/ /g)[3]?.replace(/[\(|\)]/g,'') || '-'; }")
|
||||
race_cource_desc = driver.ExecuteScript("{ return document.querySelector('div.race_tab')?.querySelectorAll('td')[11]?.textContent || '-'; } ")
|
||||
|
||||
|
||||
For i = LBound(hourse_table) To UBound(hourse_table)
|
||||
Dim temp As Variant
|
||||
temp = Split(hourse_table(i), ",")
|
||||
|
||||
startCell.Offset(current_row, 30).value = table_race_date
|
||||
startCell.Offset(current_row, 31).value = race_course
|
||||
startCell.Offset(current_row, 32).value = race_number
|
||||
startCell.Offset(current_row, 33).value = total_race_number
|
||||
startCell.Offset(current_row, 34).value = race_cource_desc
|
||||
|
||||
startCell.Offset(current_row, 37).value = temp(2)
|
||||
startCell.Offset(current_row, 38).value = temp(3)
|
||||
startCell.Offset(current_row, 39).value = temp(4)
|
||||
startCell.Offset(current_row, 40).value = "'" & temp(7)
|
||||
startCell.Offset(current_row, 41).value = temp(5)
|
||||
startCell.Offset(current_row, 42).value = temp(6)
|
||||
startCell.Offset(current_row, 35).value = temp(0)
|
||||
startCell.Offset(current_row, 36).value = temp(1)
|
||||
startCell.Offset(current_row, 49).value = "'" & temp(8)
|
||||
startCell.Offset(current_row, 50).value = temp(11)
|
||||
|
||||
Dim temp_l As Variant
|
||||
temp_l = Split(temp(12), "_")
|
||||
For k = 0 To 5
|
||||
If (k >= UBound(temp_l)) Then
|
||||
startCell.Offset(current_row, 43 + k).value = "-"
|
||||
Else
|
||||
startCell.Offset(current_row, 43 + k).value = temp_l(k)
|
||||
End If
|
||||
Next k
|
||||
|
||||
current_row = current_row + 1
|
||||
Next i
|
||||
|
||||
|
||||
Dim num_of_horse As Integer
|
||||
Dim race_row_end As Integer
|
||||
race_row_end = current_row - 1
|
||||
|
||||
num_of_horse = UBound(hourse_table)
|
||||
|
||||
not_used = DisplaySectionalTime_aspx.ScrapeDisplaySectionalTime(driver, race_date, CStr(l), race_row_end - num_of_horse, num_of_horse)
|
||||
|
||||
Next l
|
||||
|
||||
|
||||
GoTo Done
|
||||
|
||||
ErrorHandler:
|
||||
MsgBox "hello error2"
|
||||
MsgBox "Error: " & Err.Description
|
||||
|
||||
Done:
|
||||
TidySheet
|
||||
|
||||
driver.Quit
|
||||
|
||||
|
||||
End Sub
|
||||
|
||||
Function ResetCell()
|
||||
Worksheets("Sheet1").Range("AE3:BF300").ClearContents
|
||||
End Function
|
||||
|
||||
Function TidySheet()
|
||||
Worksheets("Sheet1").Range("OK1:OK200").ClearContents
|
||||
|
||||
'widen column width
|
||||
Worksheets("Sheet1").Range("AE3:BF300").Columns.AutoFit
|
||||
|
||||
' align text to center
|
||||
Worksheets("Sheet1").Range("AE3:BF300").HorizontalAlignment = xlCenter
|
||||
|
||||
End Function
|
||||
|
||||
|
||||
' write cell
|
||||
Sub writeCell(cell_addres As String, value As String)
|
||||
|
||||
End Sub
|
||||
|
||||
|
||||
Private Sub Take_ScreenShot_Desktop()
|
||||
Dim utils As New utils
|
||||
Dim driver As New ChromeDriver
|
||||
driver.Get "https://en.wikipedia.org/wiki/Main_Page"
|
||||
|
||||
Dim img As Object
|
||||
|
||||
'take a screenshot of the desktop
|
||||
Set img = utils.TakeScreenshot()
|
||||
|
||||
'save the image in the folder of the workbook
|
||||
img.SaveAs ThisWorkbook.Path & "\sc-desktop.png"
|
||||
|
||||
driver.Quit
|
||||
End Sub
|
||||
|
||||
|
||||
|
4
abc2022d/task1/ticket0001/LocalTrackwork_aspx.bas
Normal file
4
abc2022d/task1/ticket0001/LocalTrackwork_aspx.bas
Normal file
@@ -0,0 +1,4 @@
|
||||
Attribute VB_Name = "LocalTrackwork_aspx"
|
||||
|
||||
Option Explicit
|
||||
|
303
abc2022d/task1/ticket0001/Racecard_aspx.bas
Normal file
303
abc2022d/task1/ticket0001/Racecard_aspx.bas
Normal file
@@ -0,0 +1,303 @@
|
||||
Attribute VB_Name = "Racecard_aspx"
|
||||
|
||||
Option Explicit
|
||||
|
||||
Public Sub ScrapeRacecard()
|
||||
Common.ResetSheet
|
||||
|
||||
Dim COL_IDX_HORSE_NO As Integer
|
||||
Dim COL_IDX_LAST_6_RUNS As Integer
|
||||
Dim COL_IDX_COLOUR As Integer
|
||||
Dim COL_IDX_HORSE As Integer
|
||||
Dim COL_IDX_BRAND_NO As Integer
|
||||
Dim COL_IDX_WT As Integer
|
||||
Dim COL_IDX_JOCKEY As Integer
|
||||
Dim COL_IDX_OVER_WT As Integer
|
||||
Dim COL_IDX_DRAW As Integer
|
||||
Dim COL_IDX_TRAINER As Integer
|
||||
Dim COL_IDX_RTG As Integer
|
||||
Dim COL_IDX_RTG_PLUS_MINUS As Integer
|
||||
Dim COL_IDX_HORSE_WT_DECLARATION As Integer
|
||||
Dim COL_IDX_WT_PLUS_MINUS_VS_DECLARATION As Integer
|
||||
Dim COL_IDX_BEST_TIME As Integer
|
||||
Dim COL_IDX_AGE As Integer
|
||||
Dim COL_IDX_WFA As Integer
|
||||
Dim COL_IDX_SEX As Integer
|
||||
Dim COL_IDX_SEASON_STAKES As Integer
|
||||
Dim COL_IDX_PRIORITY As Integer
|
||||
Dim COL_IDX_DAYS_SINCE_LAST_RUN As Integer
|
||||
Dim COL_IDX_GEAR As Integer
|
||||
Dim COL_IDX_OWNER As Integer
|
||||
Dim COL_IDX_SIRE As Integer
|
||||
Dim COL_IDX_DAM As Integer
|
||||
Dim COL_IDX_IMPORT_CAT As Integer
|
||||
|
||||
Dim i, j, k, l, m As Integer
|
||||
Dim not_used As String
|
||||
|
||||
Dim CURRENT_DIR As String
|
||||
CURRENT_DIR = ThisWorkbook.Path
|
||||
|
||||
' Create a new instance of the WebDriver.
|
||||
Dim driver As New WebDriver
|
||||
|
||||
' Set the path to the WebDriver executable.
|
||||
driver.SetBinary CURRENT_DIR & "\Chromium\Application\chrome.exe"
|
||||
driver.AddArgument "--disable-blink-features=AutomationControlled --blink-settings=imagesEnabled=false"
|
||||
|
||||
' Start Chrome.
|
||||
driver.Start "chrome"
|
||||
|
||||
' not_used = Common.WriteCell(s"A3","helloworld")
|
||||
|
||||
Dim startCell As Range
|
||||
Set startCell = Worksheets("Sheet1").Range("A3")
|
||||
|
||||
Dim row_offset, row_offset_start As Integer
|
||||
row_offset = 0
|
||||
row_offset_start = 0
|
||||
|
||||
Dim driver1 As New WebDriver
|
||||
driver1.SetBinary CURRENT_DIR & "\Chromium\Application\chrome.exe"
|
||||
driver1.AddArgument "--disable-blink-features=AutomationControlled --blink-settings=imagesEnabled=false"
|
||||
driver1.Start "chrome"
|
||||
|
||||
driver.Get "https://racing.hkjc.com/racing/information/English/Racing/Racecard.aspx"
|
||||
Dim race_links_scraped, race_links As Variant
|
||||
race_links_scraped = driver.ExecuteScript( _
|
||||
"let links = [];" & _
|
||||
"document" & _
|
||||
" .querySelectorAll('.top_races')[0]" & _
|
||||
" .querySelectorAll('a')" & _
|
||||
" .forEach((e) => links.push(e.href));" & _
|
||||
"first_race_link = links[0].replace('RaceNo=2', 'RaceNo=1');" & _
|
||||
"links = [first_race_link, ...links];" & _
|
||||
"return links.join('||');" _
|
||||
)
|
||||
race_links = Split(race_links_scraped, "||")
|
||||
|
||||
|
||||
Dim first_race_link, last_race_link As String
|
||||
first_race_link = race_links(0)
|
||||
last_race_link = race_links(UBound(race_links))
|
||||
Dim s_date, s_loc, s_race_num As String
|
||||
Dim i_num As Integer
|
||||
|
||||
s_date = CStr(getDateFrRaceCardLink(first_race_link)(0))
|
||||
s_loc = CStr(getDateFrRaceCardLink(first_race_link)(1))
|
||||
s_race_num = CStr(getDateFrRaceCardLink(last_race_link)(2))
|
||||
i_num = CInt(s_race_num)
|
||||
|
||||
Dim race_link as Variant
|
||||
|
||||
' on error goto eh
|
||||
On Error GoTo ErrorHandler
|
||||
|
||||
|
||||
For Each race_link In race_links
|
||||
' For m = 1 To i_num 'i_num
|
||||
' Navigate to a website.
|
||||
' driver.Get "https://racing.hkjc.com/racing/information/Chinese/Racing/Racecard.aspx?RaceDate=" & s_date & "&Racecourse=" & s_loc & "&RaceNo=" & CStr(m)
|
||||
|
||||
Dim chinese_race_link as String
|
||||
chinese_race_link = replace(race_link, "English","Chinese")
|
||||
driver.Get chinese_race_link
|
||||
|
||||
driver.FindElementsByTag ("td")
|
||||
' document.querySelectorAll('#racecardlist tbody tr')[2].textContent
|
||||
|
||||
Dim race_summary_content, race_summary_result As String
|
||||
' document.querySelectorAll('.raceCard div')[6].textContent.split(',').map(l => l.replace(/\n/g,'').trim()).filter(l => l.trim() != '')
|
||||
race_summary_content = "{ return document.querySelectorAll('.raceCard div')[8]?.innerHTML.replace(/<br>/g,', ').split(', ').join('|||') }"
|
||||
race_summary_result = driver.ExecuteScript(race_summary_content)
|
||||
|
||||
Dim course_name As String
|
||||
Dim course_length As String
|
||||
Dim course_class As String
|
||||
Dim course_condition As String
|
||||
Dim mark_range As String
|
||||
|
||||
course_name = driver.ExecuteScript("{return document.querySelectorAll('.raceCard div')[8]?.innerHTML.split(/<br>/g)[2].split(', ').reverse().slice(2).join(' ')}")
|
||||
course_length = driver.ExecuteScript("{return document.querySelectorAll('.raceCard div')[8]?.innerHTML.split(/<br>/g)[2].split(', ').reverse()[1]}")
|
||||
course_class = driver.ExecuteScript("{return document.querySelectorAll('.raceCard div')[8]?.innerHTML.split(/<br>/g)[3].split(', ').reverse()[0] }")
|
||||
course_condition = driver.ExecuteScript("{return document.querySelectorAll('.raceCard div')[8]?.innerHTML.split(/<br>/g)[2].split(', ').reverse()[0] }")
|
||||
mark_range = driver.ExecuteScript("{return document.querySelectorAll('.raceCard div')[8]?.innerHTML.split(/<br>/g)[3].split(', ').reverse()[1].split(': ')[1] }")
|
||||
|
||||
row_offset_start = row_offset
|
||||
|
||||
Dim actual_horse_count As Integer
|
||||
actual_horse_count = 0
|
||||
|
||||
For j = 0 To 30
|
||||
|
||||
Dim s_test, s_test_result As String
|
||||
s_test = "{ return document.querySelectorAll('#racecardlist tbody tr td')[" & (27) + j * 27 + 1 & "]?.textContent.trim()||'not found' }"
|
||||
s_test_result = driver.ExecuteScript(s_test)
|
||||
|
||||
If (s_test_result = "not found") Then
|
||||
|
||||
Else
|
||||
actual_horse_count = actual_horse_count + 1
|
||||
|
||||
Dim horse_id As String
|
||||
|
||||
Dim s_content, s_result As String
|
||||
'1 ???? --> Horse No.
|
||||
s_content = "{ return document.querySelectorAll('#racecardlist tbody tr td')[" & (27) + j * 27 + 1 & "].textContent.trim() }"
|
||||
s_result = driver.ExecuteScript(s_content)
|
||||
startCell.Offset(row_offset, 1).value = s_result
|
||||
|
||||
'2 6??? --> Last 6 Runs
|
||||
'3 ?? --> Colour
|
||||
'4 ?? --> Horse
|
||||
s_content = "{ return document.querySelectorAll('#racecardlist tbody tr td')[" & (27) + j * 27 + 4 & "].textContent.trim() }"
|
||||
s_result = driver.ExecuteScript(s_content)
|
||||
startCell.Offset(row_offset, 2).value = s_result
|
||||
|
||||
horse_id = driver.ExecuteScript("{ return document.querySelectorAll('#racecardlist tbody tr td')[" & (27) + j * 27 + 4 & "].querySelector('a').href.split('=')[1] }")
|
||||
startCell.Offset(row_offset, 400).value = horse_id
|
||||
|
||||
'5 ?? --> Brand No.
|
||||
s_content = "{ return document.querySelectorAll('#racecardlist tbody tr td')[" & (27) + j * 27 + 5 & "].textContent.trim() }"
|
||||
s_result = driver.ExecuteScript(s_content)
|
||||
startCell.Offset(row_offset, 0).value = s_result
|
||||
|
||||
'6 ?? --> Wt.
|
||||
s_content = "{ return document.querySelectorAll('#racecardlist tbody tr td')[" & (27) + j * 27 + 6 & "].textContent.trim() }"
|
||||
s_result = driver.ExecuteScript(s_content)
|
||||
startCell.Offset(row_offset, 7).value = s_result
|
||||
|
||||
'7 ?? --> Jockey
|
||||
s_content = "{ return document.querySelectorAll('#racecardlist tbody tr td')[" & (27) + j * 27 + 7 & "].textContent.trim() }"
|
||||
s_result = driver.ExecuteScript(s_content)
|
||||
startCell.Offset(row_offset, 3).value = s_result
|
||||
|
||||
'8 ???? --> Over Wt.
|
||||
'9 ?? --> Draw
|
||||
s_content = "{ return document.querySelectorAll('#racecardlist tbody tr td')[" & (27) + j * 27 + 9 & "].textContent.trim() }"
|
||||
s_result = driver.ExecuteScript(s_content)
|
||||
startCell.Offset(row_offset, 5).value = s_result
|
||||
|
||||
'10 ??? --> Trainer
|
||||
s_content = "{ return document.querySelectorAll('#racecardlist tbody tr td')[" & (27) + j * 27 + 10 & "].textContent.trim() }"
|
||||
s_result = driver.ExecuteScript(s_content)
|
||||
startCell.Offset(row_offset, 4).value = s_result
|
||||
|
||||
'11 ?? --> Rtg.
|
||||
s_content = "{ return document.querySelectorAll('#racecardlist tbody tr td')[" & (27) + j * 27 + 12 & "].textContent.trim() }"
|
||||
s_result = driver.ExecuteScript(s_content)
|
||||
startCell.Offset(row_offset, 8).value = s_result
|
||||
|
||||
'12 ??+/- --> Rtg.+/-
|
||||
'13 ???? --> Horse Wt. (Declaration)
|
||||
s_content = "{ return document.querySelectorAll('#racecardlist tbody tr td')[" & (27) + j * 27 + 13 & "].textContent.trim() }"
|
||||
s_result = driver.ExecuteScript(s_content)
|
||||
startCell.Offset(row_offset, 9).value = s_result
|
||||
|
||||
'14 ????+/- --> Wt.+/- (vs Declaration)
|
||||
'15 ???? --> Best Time
|
||||
'16 ?? --> Age
|
||||
s_content = "{ return document.querySelectorAll('#racecardlist tbody tr td')[" & (27) + j * 27 + 17 & "].textContent.trim() }"
|
||||
s_result = driver.ExecuteScript(s_content)
|
||||
startCell.Offset(row_offset, 6).value = s_result
|
||||
|
||||
'17 ???? --> WFA
|
||||
'18 ?? --> Sex
|
||||
s_content = "{ return document.querySelectorAll('#racecardlist tbody tr td')[" & (27) + j * 27 + 19 & "].textContent.trim() }"
|
||||
s_result = driver.ExecuteScript(s_content)
|
||||
startCell.Offset(row_offset, 10).value = s_result
|
||||
|
||||
'19 ???? --> Season Stakes
|
||||
'20 ?????? --> Priority
|
||||
'21 ?????? --> Days since Last Run
|
||||
s_content = "{ return document.querySelectorAll('#racecardlist tbody tr td')[" & (27) + j * 27 + 22 & "].textContent.trim() }"
|
||||
s_result = driver.ExecuteScript(s_content)
|
||||
startCell.Offset(row_offset, 12).value = s_result
|
||||
|
||||
'22 ?? --> Gear
|
||||
s_content = "{ return document.querySelectorAll('#racecardlist tbody tr td')[" & (27) + j * 27 + 23 & "].textContent.trim() }"
|
||||
s_result = driver.ExecuteScript(s_content)
|
||||
startCell.Offset(row_offset, 11).value = s_result
|
||||
|
||||
'23 ?? --> Owner
|
||||
'24 ?? --> Sire
|
||||
s_content = "{ return document.querySelectorAll('#racecardlist tbody tr td')[" & (27) + j * 27 + 25 & "].textContent.trim() }"
|
||||
s_result = driver.ExecuteScript(s_content)
|
||||
startCell.Offset(row_offset, 13).value = s_result
|
||||
|
||||
'25 ?? --> Dam
|
||||
s_content = "{ return document.querySelectorAll('#racecardlist tbody tr td')[" & (27) + j * 27 + 26 & "].textContent.trim() }"
|
||||
s_result = driver.ExecuteScript(s_content)
|
||||
startCell.Offset(row_offset, 14).value = s_result
|
||||
|
||||
'26 ???? --> Import Cat.
|
||||
|
||||
|
||||
startCell.Offset(row_offset, 15).value = Split(race_summary_result, "|||")(1)
|
||||
startCell.Offset(row_offset, 16).value = Split(race_summary_result, "|||")(3)
|
||||
startCell.Offset(row_offset, 17).value = course_length
|
||||
startCell.Offset(row_offset, 18).value = course_name
|
||||
startCell.Offset(row_offset, 19).value = course_class
|
||||
startCell.Offset(row_offset, 20).value = course_condition
|
||||
startCell.Offset(row_offset, 21).value = mark_range
|
||||
startCell.Offset(row_offset, 22).value = Split(Split(Split(race_summary_result, "|||")(0), " - ")(0), " ")(2)
|
||||
|
||||
|
||||
not_used = Horse_aspx.ScrapeHorse(driver1, startCell.Offset(row_offset, 400).value, CStr(row_offset))
|
||||
|
||||
not_used = TrackworkResult_aspx.Scrape(driver1, startCell.Offset(row_offset, 400).value, row_offset, s_date)
|
||||
|
||||
row_offset = row_offset + 1
|
||||
End If
|
||||
|
||||
Next j
|
||||
|
||||
'not_used = LocalResults_aspx.ScrapeLocalResults(driver1, s_date, CStr(m), row_offset_start, actual_horse_count)
|
||||
'not_used = DisplaySectionalTime_aspx.ScrapeDisplaySectionalTime(driver1, s_date, CStr(m), row_offset_start, actual_horse_count)
|
||||
|
||||
' Next m
|
||||
Next race_link
|
||||
|
||||
GoTo Done
|
||||
|
||||
ErrorHandler:
|
||||
MsgBox "Error: " & Err.Description
|
||||
|
||||
Done:
|
||||
driver.Quit
|
||||
driver1.Quit
|
||||
|
||||
Common.ResumeScreenUpdate
|
||||
|
||||
Common.TidySheet
|
||||
|
||||
End Sub
|
||||
|
||||
|
||||
|
||||
' write cell
|
||||
Sub writeCell(cell_addres As String, value As String)
|
||||
|
||||
End Sub
|
||||
|
||||
|
||||
Private Sub Take_ScreenShot_Desktop()
|
||||
Dim utils As New utils
|
||||
Dim driver As New ChromeDriver
|
||||
driver.Get "https://en.wikipedia.org/wiki/Main_Page"
|
||||
|
||||
Dim img As Object
|
||||
|
||||
'take a screenshot of the desktop
|
||||
Set img = utils.TakeScreenshot()
|
||||
|
||||
'save the image in the folder of the workbook
|
||||
img.SaveAs ThisWorkbook.Path & "\sc-desktop.png"
|
||||
|
||||
driver.Quit
|
||||
End Sub
|
||||
|
||||
|
||||
|
||||
|
||||
|
122
abc2022d/task1/ticket0001/TrackworkResult_aspx.bas
Normal file
122
abc2022d/task1/ticket0001/TrackworkResult_aspx.bas
Normal file
@@ -0,0 +1,122 @@
|
||||
Attribute VB_Name = "TrackworkResult_aspx"
|
||||
|
||||
Option Explicit
|
||||
|
||||
|
||||
Public Sub test()
|
||||
'horse_id = "HK_2022_H195"
|
||||
'row_offset = 0
|
||||
Dim horse_id As String
|
||||
Dim row_offset As String
|
||||
|
||||
|
||||
' Create a new instance of the WebDriver.
|
||||
Dim driver As New WebDriver
|
||||
|
||||
' Set the path to the WebDriver executable.
|
||||
driver.SetBinary "C:\Users\logic\AppData\Local\Chromium\Application\chrome.exe"
|
||||
|
||||
' Start Chrome.
|
||||
driver.Start "chrome"
|
||||
|
||||
|
||||
Dim not_use As String
|
||||
not_use = TrackworkResult_aspx.Scrape(driver, "HK_2022_H195", 0, "2024/04/20")
|
||||
|
||||
|
||||
driver.Quit
|
||||
|
||||
End Sub
|
||||
|
||||
Public Function Scrape(driver As WebDriver, horse_id As String, ByVal row_offset As Integer, ByVal s_date As String)
|
||||
|
||||
Dim script_content As String
|
||||
|
||||
' Create a new instance of the WebDriver.
|
||||
'Dim driver As New WebDriver
|
||||
|
||||
' Set the path to the WebDriver executable.
|
||||
'driver.SetBinary "C:\Users\logic\AppData\Local\Chromium\Application\chrome.exe"
|
||||
|
||||
' Start Chrome.
|
||||
'driver.Start "chrome"
|
||||
|
||||
' Navigate to a website.
|
||||
driver.Get "https://racing.hkjc.com/racing/information/English/Trackwork/TrackworkResult.aspx?HorseId=" & horse_id
|
||||
|
||||
' document.querySelectorAll('#racecardlist tbody tr')[2].textContent
|
||||
Dim i, j As Integer
|
||||
|
||||
|
||||
Dim startCell As Range
|
||||
Set startCell = Worksheets("Sheet1").Range("A3")
|
||||
|
||||
Dim all_row As String
|
||||
|
||||
script_content = "{" & _
|
||||
"list_e = [];" & _
|
||||
"document.querySelector('div.performance table').querySelectorAll('tr').forEach((r,i) => {" & _
|
||||
" if (i > 0) list_e.push(r.textContent.replace(/\n +/g,'___').slice(3,-3));" & _
|
||||
"});" & _
|
||||
"return list_e.join('|||');" & _
|
||||
"}"
|
||||
|
||||
all_row = driver.ExecuteScript(script_content)
|
||||
|
||||
Dim table_rows As Variant
|
||||
table_rows = Split(all_row, "|||")
|
||||
|
||||
For i = 0 To UBound(table_rows) - 1
|
||||
|
||||
Dim td_s As Variant
|
||||
|
||||
Dim event_date As String
|
||||
td_s = Split(table_rows(i), "___")
|
||||
event_date = td_s(0)
|
||||
|
||||
Dim event_person as String
|
||||
td_s = Split(table_rows(i), "___")
|
||||
event_person = td_s(3)
|
||||
|
||||
|
||||
Dim date_diff As Integer
|
||||
date_diff = DateDiff("d", Common.ParseDDMMYYYY(event_date), s_date)
|
||||
|
||||
If (date_diff <= 20) Then
|
||||
If (InStr(td_s(1), "Barrier Trial") > 0) Then
|
||||
startCell.Offset(row_offset, 24).value = "Y"
|
||||
If (startCell.Offset(row_offset, 25).value = "") Then
|
||||
startCell.Offset(row_offset, 25).value = event_date
|
||||
Else
|
||||
startCell.Offset(row_offset, 25).value = startCell.Offset(row_offset, 25).value & "," & event_date
|
||||
End If
|
||||
End If
|
||||
|
||||
|
||||
If (InStr(td_s(1), "Gallop") > 0) Then
|
||||
' Gallop by R.B. ?
|
||||
if (InStr(event_person, "R.B.") > 0) Then
|
||||
startCell.Offset(row_offset, 26).value = "Y"
|
||||
end if
|
||||
|
||||
If (startCell.Offset(row_offset, 27).value = "") Then
|
||||
startCell.Offset(row_offset, 27).value = event_date
|
||||
Else
|
||||
startCell.Offset(row_offset, 27).value = startCell.Offset(row_offset, 27).value & "," & event_date
|
||||
' Dim current_cell As Variant
|
||||
' Set current_cell = startCell.Offset(0, 27)
|
||||
' current_cell.Hyperlinks.Add Anchor:=current_cell, Address:="https://racing.hkjc.com/racing/information/Chinese/Horse/Horse.aspx?HorseId=" & horse_id
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
|
||||
Next
|
||||
|
||||
'driver.Quit
|
||||
|
||||
End Function
|
||||
|
||||
|
||||
|
||||
|
||||
|
5
abc2022d/task1/ticket0001/dev.bat
Normal file
5
abc2022d/task1/ticket0001/dev.bat
Normal file
@@ -0,0 +1,5 @@
|
||||
@REM start excel by yourself
|
||||
|
||||
@REM ./test.xlsm
|
||||
|
||||
xlwings vba edit --file ./main.xlsm
|
3
abc2022d/task1/ticket0001/gitUpdate.bat
Normal file
3
abc2022d/task1/ticket0001/gitUpdate.bat
Normal file
@@ -0,0 +1,3 @@
|
||||
git add .
|
||||
git commit -m"update ticket0001,"
|
||||
start git push
|
17
abc2022d/task1/ticket0001/history.md
Normal file
17
abc2022d/task1/ticket0001/history.md
Normal file
@@ -0,0 +1,17 @@
|
||||
# history
|
||||
|
||||
## ticket0001
|
||||
|
||||
### Q
|
||||
|
||||
Hello 你好, 關於之前揾你幫手寫個 VBA , 發現了有 error 想揾你 fix
|
||||
|
||||
以下圖第 6 場 4 號勤德威力為例,
|
||||
我剛 gen 左個 excel ,
|
||||
發現佢無試閘但 vba show 左佢有試閘同試閘日期,
|
||||
同埋佢快操日期亦錯,
|
||||
以及佢之前 ge 快操並沒有由副練去做,
|
||||
煩請更正,
|
||||
謝謝
|
||||
|
||||
### Drill
|
BIN
abc2022d/task1/ticket0001/main.xlsm
Normal file
BIN
abc2022d/task1/ticket0001/main.xlsm
Normal file
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 65 KiB |
75
abc2022d/task1/ticket0002/Common.bas
Normal file
75
abc2022d/task1/ticket0002/Common.bas
Normal file
@@ -0,0 +1,75 @@
|
||||
Attribute VB_Name = "Common"
|
||||
|
||||
Option Explicit
|
||||
|
||||
Global CURRENT_DIR As String
|
||||
|
||||
Function getDateFrRaceCardLink(ByVal in_str As String)
|
||||
' https://racing.hkjc.com/racing/information/English/Racing/Racecard.aspx?RaceDate=2024/04/24&Racecourse=HV&RaceNo=2
|
||||
Dim s_date, s_loc, s_race_num As String
|
||||
s_date = Split(Split(in_str, "=")(1), "&")(0)
|
||||
s_loc = Split(Split(in_str, "=")(2), "&")(0)
|
||||
s_race_num = Split(in_str, "=")(3)
|
||||
|
||||
getDateFrRaceCardLink = Array(s_date, s_loc, s_race_num)
|
||||
End Function
|
||||
|
||||
Function readCell(cell_address As String)
|
||||
Dim temp As String
|
||||
temp = Worksheets("Sheet1").Range(cell_address).value
|
||||
readCell = temp
|
||||
End Function
|
||||
|
||||
Function writeCell(cell_address As String, content As String)
|
||||
'write cell according to cell_address and content
|
||||
Worksheets("Sheet1").Range(cell_address).value = content
|
||||
|
||||
writeCell = content
|
||||
End Function
|
||||
|
||||
|
||||
Function ResetSheet()
|
||||
Worksheets("Sheet1").Range("A3:AC200").ClearContents
|
||||
End Function
|
||||
|
||||
|
||||
Function TidySheet()
|
||||
Worksheets("Sheet1").Range("OK1:OK200").ClearContents
|
||||
|
||||
'widen column width
|
||||
Worksheets("Sheet1").Range("A2:DF200").Columns.AutoFit
|
||||
|
||||
' align text to center
|
||||
Worksheets("Sheet1").Range("A2:DF200").HorizontalAlignment = xlCenter
|
||||
|
||||
End Function
|
||||
|
||||
|
||||
Function ParseDDMMYYYY(input_string As String)
|
||||
Dim s_day As String
|
||||
Dim s_month As String
|
||||
Dim s_year As String
|
||||
|
||||
s_day = Split(input_string, "/")(0)
|
||||
s_month = Split(input_string, "/")(1)
|
||||
s_year = Split(input_string, "/")(2)
|
||||
|
||||
ParseDDMMYYYY = DateSerial(CInt(s_year), CInt(s_month), CInt(s_day))
|
||||
End Function
|
||||
|
||||
Sub DisableScreenUpdate
|
||||
Application.ScreenUpdating = False 'disable screen updating
|
||||
Application.Calculation = xlCalculationManual 'disable automatic calculation
|
||||
Application.EnableEvents = False 'disable event handling
|
||||
Application.DisplayAlerts = False 'disable alerts
|
||||
|
||||
end sub
|
||||
|
||||
|
||||
sub ResumeScreenUpdate
|
||||
Application.ScreenUpdating = True 'enable screen updating
|
||||
Application.Calculation = xlCalculationAutomatic 'enable automatic calculation
|
||||
Application.EnableEvents = True 'enable event handling
|
||||
Application.DisplayAlerts = True 'enable alerts
|
||||
|
||||
end sub
|
163
abc2022d/task1/ticket0002/DisplaySectionalTime_aspx.bas
Normal file
163
abc2022d/task1/ticket0002/DisplaySectionalTime_aspx.bas
Normal file
@@ -0,0 +1,163 @@
|
||||
Attribute VB_Name = "DisplaySectionalTime_aspx"
|
||||
|
||||
Option Explicit
|
||||
|
||||
|
||||
Public Function ScrapeDisplaySectionalTime(driver As WebDriver, ByVal race_date As String, race_num As String, row_offset As Integer, ByVal horse_count As Integer)
|
||||
Dim COL_IDX_HORSE_NO As Integer
|
||||
Dim COL_IDX_LAST_6_RUNS As Integer
|
||||
Dim COL_IDX_COLOUR As Integer
|
||||
Dim COL_IDX_HORSE As Integer
|
||||
Dim COL_IDX_BRAND_NO As Integer
|
||||
Dim COL_IDX_WT As Integer
|
||||
Dim COL_IDX_JOCKEY As Integer
|
||||
Dim COL_IDX_OVER_WT As Integer
|
||||
Dim COL_IDX_DRAW As Integer
|
||||
Dim COL_IDX_TRAINER As Integer
|
||||
Dim COL_IDX_RTG As Integer
|
||||
Dim COL_IDX_RTG_PLUS_MINUS As Integer
|
||||
Dim COL_IDX_HORSE_WT_DECLARATION As Integer
|
||||
Dim COL_IDX_WT_PLUS_MINUS_VS_DECLARATION As Integer
|
||||
Dim COL_IDX_BEST_TIME As Integer
|
||||
Dim COL_IDX_AGE As Integer
|
||||
Dim COL_IDX_WFA As Integer
|
||||
Dim COL_IDX_SEX As Integer
|
||||
Dim COL_IDX_SEASON_STAKES As Integer
|
||||
Dim COL_IDX_PRIORITY As Integer
|
||||
Dim COL_IDX_DAYS_SINCE_LAST_RUN As Integer
|
||||
Dim COL_IDX_GEAR As Integer
|
||||
Dim COL_IDX_OWNER As Integer
|
||||
Dim COL_IDX_SIRE As Integer
|
||||
Dim COL_IDX_DAM As Integer
|
||||
Dim COL_IDX_IMPORT_CAT As Integer
|
||||
|
||||
Dim script_content, script_result As String
|
||||
|
||||
Dim i, j As Integer
|
||||
|
||||
|
||||
On Error GoTo ErrorHandler
|
||||
|
||||
' Navigate to a website.
|
||||
Dim s_year, s_month, s_date, temp_new_date As String
|
||||
s_year = Split(race_date, "/")(0)
|
||||
s_month = Split(race_date, "/")(1)
|
||||
s_date = Split(race_date, "/")(2)
|
||||
temp_new_date = s_date & "/" & s_month & "/" & s_year
|
||||
Dim s_race_date As String
|
||||
s_race_date = Format(temp_new_date, "DD/MM/YYYY")
|
||||
|
||||
driver.Get "https://racing.hkjc.com/racing/information/chinese/Racing/DisplaySectionalTime.aspx?RaceDate=" & s_race_date & "&RaceNo=" & race_num
|
||||
|
||||
|
||||
Dim startCell As Range
|
||||
Set startCell = Worksheets("Sheet1").Range("A3")
|
||||
|
||||
|
||||
|
||||
' test if match result table found
|
||||
Dim table_count, table_count_result As String
|
||||
table_count_result = driver.ExecuteScript("{ return document?.querySelectorAll('.Race').length }")
|
||||
table_count = CInt(table_count_result)
|
||||
|
||||
|
||||
If (table_count > 0) Then
|
||||
|
||||
|
||||
|
||||
Dim hourse_table As Variant
|
||||
script_content = "{" & _
|
||||
" list_e = [];" & _
|
||||
" document" & _
|
||||
" .querySelector('table.race_table')" & _
|
||||
" .querySelectorAll('tr')" & _
|
||||
" .forEach((e_tr, idx) => {" & _
|
||||
" if (idx > 2) {" & _
|
||||
" list_td = [];" & _
|
||||
" temp = e_tr.querySelectorAll('td');" & _
|
||||
" list_td.push(temp[2].textContent.replace(/[\(\)]/g,'').split(/\s/g)[1]);" & _
|
||||
" list_td.push(temp[3]?.querySelectorAll('p')[1]?.textContent.replace(/\n/g, '')?.split(/\s+/g)[0] || '-');" & _
|
||||
" list_td.push(temp[4]?.querySelectorAll('p')[1]?.textContent.replace(/\n/g, '')?.split(/\s+/g)[0] || '-');" & _
|
||||
" list_td.push(temp[5]?.querySelectorAll('p')[1]?.textContent.replace(/\n/g, '')?.split(/\s+/g)[0] || '-');" & _
|
||||
" list_td.push(temp[6]?.querySelectorAll('p')[1]?.textContent.replace(/\n/g, '')?.split(/\s+/g)[0] || '-');" & _
|
||||
" list_td.push(temp[7]?.querySelectorAll('p')[1]?.textContent.replace(/\n/g, '')?.split(/\s+/g)[0] || '-');" & _
|
||||
" list_td.push(temp[8]?.querySelectorAll('p')[1]?.textContent.replace(/\n/g, '')?.split(/\s+/g)[0] || '-');" & _
|
||||
" list_td.push(temp[9]?.textContent);" & _
|
||||
" list_e.push(list_td.join(','));" & _
|
||||
" }" & _
|
||||
" });" & _
|
||||
" return list_e.join('|||'); " & _
|
||||
"}"
|
||||
script_result = driver.ExecuteScript(script_content)
|
||||
hourse_table = Split(script_result, "|||")
|
||||
|
||||
'Country of origin
|
||||
' document.querySelector('table.race_table').querySelectorAll('tr')[2+1].querySelectorAll('td')[0-9]
|
||||
For i = LBound(hourse_table) To UBound(hourse_table)
|
||||
For j = LBound(hourse_table) To UBound(hourse_table)
|
||||
Dim temp As Variant
|
||||
temp = Split(hourse_table(j), ",")
|
||||
Dim horse_id As String
|
||||
|
||||
|
||||
If (InStr(startCell.Offset(row_offset + i, 37).value, temp(0)) > 0) Then
|
||||
startCell.Offset(row_offset + i, 51 + 0).value = temp(1)
|
||||
startCell.Offset(row_offset + i, 51 + 1).value = temp(2)
|
||||
startCell.Offset(row_offset + i, 51 + 2).value = temp(3)
|
||||
startCell.Offset(row_offset + i, 51 + 3).value = temp(4)
|
||||
startCell.Offset(row_offset + i, 51 + 4).value = temp(5)
|
||||
startCell.Offset(row_offset + i, 51 + 5).value = temp(6)
|
||||
startCell.Offset(row_offset + i, 51 + 6).value = "'" & temp(7)
|
||||
End If
|
||||
Next j
|
||||
Next i
|
||||
|
||||
|
||||
Else
|
||||
For j = 0 To horse_count - 1
|
||||
' table not ready yet
|
||||
startCell.Offset(row_offset + j, 30).value = "HKJC table not ready"
|
||||
Next j
|
||||
|
||||
End If
|
||||
|
||||
GoTo Done
|
||||
|
||||
ErrorHandler:
|
||||
MsgBox "hello error ?"
|
||||
MsgBox "Error: " & Err.Description
|
||||
|
||||
Done:
|
||||
Debug.Print "hello done"
|
||||
|
||||
|
||||
End Function
|
||||
|
||||
|
||||
|
||||
' write cell
|
||||
Sub writeCell(cell_addres As String, value As String)
|
||||
|
||||
End Sub
|
||||
|
||||
|
||||
Private Sub Take_ScreenShot_Desktop()
|
||||
Dim utils As New utils
|
||||
Dim driver As New ChromeDriver
|
||||
driver.Get "https://en.wikipedia.org/wiki/Main_Page"
|
||||
|
||||
Dim img As Object
|
||||
|
||||
'take a screenshot of the desktop
|
||||
Set img = utils.TakeScreenshot()
|
||||
|
||||
'save the image in the folder of the workbook
|
||||
img.SaveAs ThisWorkbook.Path & "\sc-desktop.png"
|
||||
|
||||
driver.Quit
|
||||
End Sub
|
||||
|
||||
|
||||
|
||||
|
||||
|
5
abc2022d/task1/ticket0002/Helloworld.bas
Normal file
5
abc2022d/task1/ticket0002/Helloworld.bas
Normal file
@@ -0,0 +1,5 @@
|
||||
Attribute VB_Name = "Helloworld"
|
||||
Sub TestHelloworld()
|
||||
|
||||
|
||||
End Sub
|
87
abc2022d/task1/ticket0002/Horse_aspx.bas
Normal file
87
abc2022d/task1/ticket0002/Horse_aspx.bas
Normal file
@@ -0,0 +1,87 @@
|
||||
Attribute VB_Name = "Horse_aspx"
|
||||
|
||||
Option Explicit
|
||||
|
||||
|
||||
Public Function ScrapeHorse(driver As WebDriver, horse_id As String, row_offset As String)
|
||||
Dim COL_IDX_HORSE_NO As Integer
|
||||
Dim COL_IDX_LAST_6_RUNS As Integer
|
||||
Dim COL_IDX_COLOUR As Integer
|
||||
Dim COL_IDX_HORSE As Integer
|
||||
Dim COL_IDX_BRAND_NO As Integer
|
||||
Dim COL_IDX_WT As Integer
|
||||
Dim COL_IDX_JOCKEY As Integer
|
||||
Dim COL_IDX_OVER_WT As Integer
|
||||
Dim COL_IDX_DRAW As Integer
|
||||
Dim COL_IDX_TRAINER As Integer
|
||||
Dim COL_IDX_RTG As Integer
|
||||
Dim COL_IDX_RTG_PLUS_MINUS As Integer
|
||||
Dim COL_IDX_HORSE_WT_DECLARATION As Integer
|
||||
Dim COL_IDX_WT_PLUS_MINUS_VS_DECLARATION As Integer
|
||||
Dim COL_IDX_BEST_TIME As Integer
|
||||
Dim COL_IDX_AGE As Integer
|
||||
Dim COL_IDX_WFA As Integer
|
||||
Dim COL_IDX_SEX As Integer
|
||||
Dim COL_IDX_SEASON_STAKES As Integer
|
||||
Dim COL_IDX_PRIORITY As Integer
|
||||
Dim COL_IDX_DAYS_SINCE_LAST_RUN As Integer
|
||||
Dim COL_IDX_GEAR As Integer
|
||||
Dim COL_IDX_OWNER As Integer
|
||||
Dim COL_IDX_SIRE As Integer
|
||||
Dim COL_IDX_DAM As Integer
|
||||
Dim COL_IDX_IMPORT_CAT As Integer
|
||||
|
||||
Dim script_content As String
|
||||
|
||||
' ' Create a new instance of the WebDriver.
|
||||
' Dim driver As New WebDriver
|
||||
|
||||
' ' Set the path to the WebDriver executable.
|
||||
' driver.SetBinary "C:\Users\logic\AppData\Local\Chromium\Application\chrome.exe"
|
||||
|
||||
' ' Start Chrome.
|
||||
' driver.Start "chrome"
|
||||
|
||||
' Navigate to a website.
|
||||
driver.Get "https://racing.hkjc.com/racing/information/Chinese/Horse/Horse.aspx?HorseId=" & horse_id
|
||||
|
||||
' document.querySelectorAll('#racecardlist tbody tr')[2].textContent
|
||||
Dim i, j As Integer
|
||||
|
||||
|
||||
Dim startCell As Range
|
||||
Set startCell = Worksheets("Sheet1").Range("A3")
|
||||
|
||||
|
||||
'Country of origin
|
||||
' document.querySelector('table.horseProfile').querySelectorAll('td')[6].querySelectorAll('td')[2]
|
||||
script_content = "{ return document.querySelector('table.horseProfile').querySelectorAll('td')[6].querySelectorAll('td')[2].textContent.trim().split('/')[0].trim() }"
|
||||
startCell.Offset(row_offset, 28).value = driver.ExecuteScript(script_content)
|
||||
|
||||
'import type
|
||||
' document.querySelector('table.horseProfile').querySelectorAll('td')[6].querySelectorAll('td')[8]
|
||||
script_content = "{ return document.querySelector('table.horseProfile').querySelectorAll('td')[6].querySelectorAll('td')[8].textContent.trim() }"
|
||||
|
||||
End Function
|
||||
|
||||
|
||||
|
||||
Private Sub Take_ScreenShot_Desktop()
|
||||
Dim utils As New utils
|
||||
Dim driver As New ChromeDriver
|
||||
driver.Get "https://en.wikipedia.org/wiki/Main_Page"
|
||||
|
||||
Dim img As Object
|
||||
|
||||
'take a screenshot of the desktop
|
||||
Set img = utils.TakeScreenshot()
|
||||
|
||||
'save the image in the folder of the workbook
|
||||
img.SaveAs ThisWorkbook.Path & "\sc-desktop.png"
|
||||
|
||||
driver.Quit
|
||||
End Sub
|
||||
|
||||
|
||||
|
||||
|
243
abc2022d/task1/ticket0002/LocalResults_aspx.bas
Normal file
243
abc2022d/task1/ticket0002/LocalResults_aspx.bas
Normal file
@@ -0,0 +1,243 @@
|
||||
Attribute VB_Name = "LocalResults_aspx"
|
||||
|
||||
Option Explicit
|
||||
|
||||
|
||||
Public Sub ScrapeLocalResults()
|
||||
Dim COL_IDX_HORSE_NO As Integer
|
||||
Dim COL_IDX_LAST_6_RUNS As Integer
|
||||
Dim COL_IDX_COLOUR As Integer
|
||||
Dim COL_IDX_HORSE As Integer
|
||||
Dim COL_IDX_BRAND_NO As Integer
|
||||
Dim COL_IDX_WT As Integer
|
||||
Dim COL_IDX_JOCKEY As Integer
|
||||
Dim COL_IDX_OVER_WT As Integer
|
||||
Dim COL_IDX_DRAW As Integer
|
||||
Dim COL_IDX_TRAINER As Integer
|
||||
Dim COL_IDX_RTG As Integer
|
||||
Dim COL_IDX_RTG_PLUS_MINUS As Integer
|
||||
Dim COL_IDX_HORSE_WT_DECLARATION As Integer
|
||||
Dim COL_IDX_WT_PLUS_MINUS_VS_DECLARATION As Integer
|
||||
Dim COL_IDX_BEST_TIME As Integer
|
||||
Dim COL_IDX_AGE As Integer
|
||||
Dim COL_IDX_WFA As Integer
|
||||
Dim COL_IDX_SEX As Integer
|
||||
Dim COL_IDX_SEASON_STAKES As Integer
|
||||
Dim COL_IDX_PRIORITY As Integer
|
||||
Dim COL_IDX_DAYS_SINCE_LAST_RUN As Integer
|
||||
Dim COL_IDX_GEAR As Integer
|
||||
Dim COL_IDX_OWNER As Integer
|
||||
Dim COL_IDX_SIRE As Integer
|
||||
Dim COL_IDX_DAM As Integer
|
||||
Dim COL_IDX_IMPORT_CAT As Integer
|
||||
|
||||
Dim not_used As Variant
|
||||
|
||||
On Error GoTo ErrorHandler
|
||||
ResetCell
|
||||
|
||||
Dim race_date As String
|
||||
Dim s_year, s_month, s_date, temp_new_date As String
|
||||
race_date = Common.readCell("AE1")
|
||||
|
||||
s_year = Split(race_date, "/")(0)
|
||||
s_month = Split(race_date, "/")(1)
|
||||
s_date = Split(race_date, "/")(2)
|
||||
temp_new_date = s_date & "/" & s_month & "/" & s_year
|
||||
|
||||
Dim s_race_date As String
|
||||
s_race_date = Format(temp_new_date, "DD/MM/YYYY")
|
||||
|
||||
|
||||
'ByVal race_date As String, race_num As String, row_offset As Integer, horse_count As Integer
|
||||
Dim row_offset As Integer
|
||||
row_offset = 0
|
||||
|
||||
' on error goto eh
|
||||
On Error GoTo ErrorHandler
|
||||
|
||||
' Create a new instance of the WebDriver.
|
||||
Dim driver As New WebDriver
|
||||
|
||||
' Set the path to the WebDriver executable.
|
||||
|
||||
Dim CURRENT_DIR As String
|
||||
CURRENT_DIR = ThisWorkbook.Path
|
||||
driver.SetBinary CURRENT_DIR & "\Chromium\Application\chrome.exe"
|
||||
driver.AddArgument "--disable-blink-features=AutomationControlled --blink-settings=imagesEnabled=false"
|
||||
|
||||
' Start Chrome.
|
||||
driver.Start "chrome"
|
||||
|
||||
|
||||
Dim By As New By
|
||||
' Navigate to a website.
|
||||
' https://racing.hkjc.com/racing/information/Chinese/Racing/LocalResults.aspx?RaceDate=2024/04/20&Racecourse=ST&RaceNo=1
|
||||
driver.Get "https://racing.hkjc.com/racing/information/Chinese/Racing/LocalResults.aspx?RaceDate=" & s_race_date & "&RaceNo=1"
|
||||
|
||||
' document.querySelectorAll('#racecardlist tbody tr')[2].textContent
|
||||
|
||||
Dim startCell As Range
|
||||
Set startCell = Worksheets("Sheet1").Range("A3")
|
||||
|
||||
Dim hourse_number As String
|
||||
Dim script_content, script_result As String
|
||||
Dim hourse_table As Variant
|
||||
|
||||
|
||||
' test if match result table found
|
||||
Dim table_count, table_count_result As String
|
||||
table_count_result = driver.ExecuteScript("{ return document.querySelectorAll('.performance').length }")
|
||||
table_count = CInt(table_count_result)
|
||||
|
||||
' find max race_num
|
||||
Dim max_race_num As Integer
|
||||
|
||||
script_content = "{" & _
|
||||
" let all_a = {};" & _
|
||||
" all_a = document.querySelectorAll('.top_races a');" & _
|
||||
" return all_a?.item(all_a?.length-2)?.href?.split('=')[3] || 0;" & _
|
||||
"}"
|
||||
|
||||
|
||||
max_race_num = CInt(driver.ExecuteScript(script_content))
|
||||
|
||||
Dim i, j, k, l As Integer
|
||||
|
||||
Dim current_row As Integer
|
||||
current_row = row_offset
|
||||
|
||||
|
||||
For l = 1 To max_race_num
|
||||
driver.Get "https://racing.hkjc.com/racing/information/Chinese/Racing/LocalResults.aspx?RaceDate=" & race_date & "&RaceNo=" & CStr(l)
|
||||
script_content = "{" & _
|
||||
"list_e = [];" & _
|
||||
"document" & _
|
||||
" .querySelector('.performance table')" & _
|
||||
" .querySelectorAll('tr')" & _
|
||||
" .forEach((e_tr, idx) => {" & _
|
||||
" if (idx > 0) {" & _
|
||||
" let temp = e_tr.querySelectorAll('td');" & _
|
||||
" let temp_l = [];" & _
|
||||
" temp.forEach(e => temp_l.push(e.textContent.trim()));" & _
|
||||
" list_e.push(" & _
|
||||
" [" & _
|
||||
" temp_l.join(',')," & _
|
||||
" temp[9].textContent.replace(/[\n| ]+/g, '_').slice(1,-1)," & _
|
||||
" ].join(',')" & _
|
||||
" );" & _
|
||||
" }" & _
|
||||
" });" & _
|
||||
"return list_e.join('|||')" & _
|
||||
"}"
|
||||
script_result = driver.ExecuteScript(script_content)
|
||||
hourse_table = Split(script_result, "|||")
|
||||
|
||||
Dim table_race_date, race_course, race_number, total_race_number, race_cource_desc As String
|
||||
table_race_date = driver.ExecuteScript("{ return document.querySelector('div.raceMeeting_select')?.querySelectorAll('p')[0]?.querySelectorAll('span')[0]?.textContent.split(/ +/g)[1] || '-'}")
|
||||
race_course = driver.ExecuteScript("{ return document.querySelector('div.raceMeeting_select')?.querySelectorAll('p')[0]?.querySelectorAll('span')[0]?.textContent.split(/ +/g)[3] || '-'}")
|
||||
race_number = driver.ExecuteScript("{ return document.querySelectorAll('div.race_tab td')[0]?.textContent?.split(/\s\(/g)[0] || '-'; }")
|
||||
total_race_number = driver.ExecuteScript("{ return document.querySelectorAll('div.race_tab td')[0]?.textContent?.split(/ /g)[3]?.replace(/[\(|\)]/g,'') || '-'; }")
|
||||
race_cource_desc = driver.ExecuteScript("{ return document.querySelector('div.race_tab')?.querySelectorAll('td')[11]?.textContent || '-'; } ")
|
||||
|
||||
|
||||
For i = LBound(hourse_table) To UBound(hourse_table)
|
||||
Dim temp As Variant
|
||||
temp = Split(hourse_table(i), ",")
|
||||
|
||||
startCell.Offset(current_row, 30).value = table_race_date
|
||||
startCell.Offset(current_row, 31).value = race_course
|
||||
startCell.Offset(current_row, 32).value = race_number
|
||||
startCell.Offset(current_row, 33).value = total_race_number
|
||||
startCell.Offset(current_row, 34).value = race_cource_desc
|
||||
|
||||
startCell.Offset(current_row, 37).value = temp(2)
|
||||
startCell.Offset(current_row, 38).value = temp(3)
|
||||
startCell.Offset(current_row, 39).value = temp(4)
|
||||
startCell.Offset(current_row, 40).value = "'" & temp(7)
|
||||
startCell.Offset(current_row, 41).value = temp(5)
|
||||
startCell.Offset(current_row, 42).value = temp(6)
|
||||
startCell.Offset(current_row, 35).value = temp(0)
|
||||
startCell.Offset(current_row, 36).value = temp(1)
|
||||
startCell.Offset(current_row, 49).value = "'" & temp(8)
|
||||
startCell.Offset(current_row, 50).value = temp(11)
|
||||
|
||||
Dim temp_l As Variant
|
||||
temp_l = Split(temp(12), "_")
|
||||
For k = 0 To 5
|
||||
If (k >= UBound(temp_l)) Then
|
||||
startCell.Offset(current_row, 43 + k).value = "-"
|
||||
Else
|
||||
startCell.Offset(current_row, 43 + k).value = temp_l(k)
|
||||
End If
|
||||
Next k
|
||||
|
||||
current_row = current_row + 1
|
||||
Next i
|
||||
|
||||
|
||||
Dim num_of_horse As Integer
|
||||
Dim race_row_end As Integer
|
||||
race_row_end = current_row - 1
|
||||
|
||||
num_of_horse = UBound(hourse_table)
|
||||
|
||||
not_used = DisplaySectionalTime_aspx.ScrapeDisplaySectionalTime(driver, race_date, CStr(l), race_row_end - num_of_horse, num_of_horse)
|
||||
|
||||
Next l
|
||||
|
||||
|
||||
GoTo Done
|
||||
|
||||
ErrorHandler:
|
||||
MsgBox "hello error2"
|
||||
MsgBox "Error: " & Err.Description
|
||||
|
||||
Done:
|
||||
TidySheet
|
||||
|
||||
driver.Quit
|
||||
|
||||
|
||||
End Sub
|
||||
|
||||
Function ResetCell()
|
||||
Worksheets("Sheet1").Range("AE3:BF300").ClearContents
|
||||
End Function
|
||||
|
||||
Function TidySheet()
|
||||
Worksheets("Sheet1").Range("OK1:OK200").ClearContents
|
||||
|
||||
'widen column width
|
||||
Worksheets("Sheet1").Range("AE3:BF300").Columns.AutoFit
|
||||
|
||||
' align text to center
|
||||
Worksheets("Sheet1").Range("AE3:BF300").HorizontalAlignment = xlCenter
|
||||
|
||||
End Function
|
||||
|
||||
|
||||
' write cell
|
||||
Sub writeCell(cell_addres As String, value As String)
|
||||
|
||||
End Sub
|
||||
|
||||
|
||||
Private Sub Take_ScreenShot_Desktop()
|
||||
Dim utils As New utils
|
||||
Dim driver As New ChromeDriver
|
||||
driver.Get "https://en.wikipedia.org/wiki/Main_Page"
|
||||
|
||||
Dim img As Object
|
||||
|
||||
'take a screenshot of the desktop
|
||||
Set img = utils.TakeScreenshot()
|
||||
|
||||
'save the image in the folder of the workbook
|
||||
img.SaveAs ThisWorkbook.Path & "\sc-desktop.png"
|
||||
|
||||
driver.Quit
|
||||
End Sub
|
||||
|
||||
|
||||
|
4
abc2022d/task1/ticket0002/LocalTrackwork_aspx.bas
Normal file
4
abc2022d/task1/ticket0002/LocalTrackwork_aspx.bas
Normal file
@@ -0,0 +1,4 @@
|
||||
Attribute VB_Name = "LocalTrackwork_aspx"
|
||||
|
||||
Option Explicit
|
||||
|
303
abc2022d/task1/ticket0002/Racecard_aspx.bas
Normal file
303
abc2022d/task1/ticket0002/Racecard_aspx.bas
Normal file
@@ -0,0 +1,303 @@
|
||||
Attribute VB_Name = "Racecard_aspx"
|
||||
|
||||
Option Explicit
|
||||
|
||||
Public Sub ScrapeRacecard()
|
||||
Common.ResetSheet
|
||||
|
||||
Dim COL_IDX_HORSE_NO As Integer
|
||||
Dim COL_IDX_LAST_6_RUNS As Integer
|
||||
Dim COL_IDX_COLOUR As Integer
|
||||
Dim COL_IDX_HORSE As Integer
|
||||
Dim COL_IDX_BRAND_NO As Integer
|
||||
Dim COL_IDX_WT As Integer
|
||||
Dim COL_IDX_JOCKEY As Integer
|
||||
Dim COL_IDX_OVER_WT As Integer
|
||||
Dim COL_IDX_DRAW As Integer
|
||||
Dim COL_IDX_TRAINER As Integer
|
||||
Dim COL_IDX_RTG As Integer
|
||||
Dim COL_IDX_RTG_PLUS_MINUS As Integer
|
||||
Dim COL_IDX_HORSE_WT_DECLARATION As Integer
|
||||
Dim COL_IDX_WT_PLUS_MINUS_VS_DECLARATION As Integer
|
||||
Dim COL_IDX_BEST_TIME As Integer
|
||||
Dim COL_IDX_AGE As Integer
|
||||
Dim COL_IDX_WFA As Integer
|
||||
Dim COL_IDX_SEX As Integer
|
||||
Dim COL_IDX_SEASON_STAKES As Integer
|
||||
Dim COL_IDX_PRIORITY As Integer
|
||||
Dim COL_IDX_DAYS_SINCE_LAST_RUN As Integer
|
||||
Dim COL_IDX_GEAR As Integer
|
||||
Dim COL_IDX_OWNER As Integer
|
||||
Dim COL_IDX_SIRE As Integer
|
||||
Dim COL_IDX_DAM As Integer
|
||||
Dim COL_IDX_IMPORT_CAT As Integer
|
||||
|
||||
Dim i, j, k, l, m As Integer
|
||||
Dim not_used As String
|
||||
|
||||
Dim CURRENT_DIR As String
|
||||
CURRENT_DIR = ThisWorkbook.Path
|
||||
|
||||
' Create a new instance of the WebDriver.
|
||||
Dim driver As New WebDriver
|
||||
|
||||
' Set the path to the WebDriver executable.
|
||||
driver.SetBinary CURRENT_DIR & "\Chromium\Application\chrome.exe"
|
||||
driver.AddArgument "--disable-blink-features=AutomationControlled --blink-settings=imagesEnabled=false"
|
||||
|
||||
' Start Chrome.
|
||||
driver.Start "chrome"
|
||||
|
||||
' not_used = Common.WriteCell(s"A3","helloworld")
|
||||
|
||||
Dim startCell As Range
|
||||
Set startCell = Worksheets("Sheet1").Range("A3")
|
||||
|
||||
Dim row_offset, row_offset_start As Integer
|
||||
row_offset = 0
|
||||
row_offset_start = 0
|
||||
|
||||
Dim driver1 As New WebDriver
|
||||
driver1.SetBinary CURRENT_DIR & "\Chromium\Application\chrome.exe"
|
||||
driver1.AddArgument "--disable-blink-features=AutomationControlled --blink-settings=imagesEnabled=false"
|
||||
driver1.Start "chrome"
|
||||
|
||||
driver.Get "https://racing.hkjc.com/racing/information/English/Racing/Racecard.aspx"
|
||||
Dim race_links_scraped, race_links As Variant
|
||||
race_links_scraped = driver.ExecuteScript( _
|
||||
"let links = [];" & _
|
||||
"document" & _
|
||||
" .querySelectorAll('.top_races')[0]" & _
|
||||
" .querySelectorAll('a')" & _
|
||||
" .forEach((e) => links.push(e.href));" & _
|
||||
"first_race_link = links[0].replace('RaceNo=2', 'RaceNo=1');" & _
|
||||
"links = [first_race_link, ...links];" & _
|
||||
"return links.join('||');" _
|
||||
)
|
||||
race_links = Split(race_links_scraped, "||")
|
||||
|
||||
|
||||
Dim first_race_link, last_race_link As String
|
||||
first_race_link = race_links(0)
|
||||
last_race_link = race_links(UBound(race_links))
|
||||
Dim s_date, s_loc, s_race_num As String
|
||||
Dim i_num As Integer
|
||||
|
||||
s_date = CStr(getDateFrRaceCardLink(first_race_link)(0))
|
||||
s_loc = CStr(getDateFrRaceCardLink(first_race_link)(1))
|
||||
s_race_num = CStr(getDateFrRaceCardLink(last_race_link)(2))
|
||||
i_num = CInt(s_race_num)
|
||||
|
||||
Dim race_link as Variant
|
||||
|
||||
' on error goto eh
|
||||
On Error GoTo ErrorHandler
|
||||
|
||||
|
||||
For Each race_link In race_links
|
||||
' For m = 1 To i_num 'i_num
|
||||
' Navigate to a website.
|
||||
' driver.Get "https://racing.hkjc.com/racing/information/Chinese/Racing/Racecard.aspx?RaceDate=" & s_date & "&Racecourse=" & s_loc & "&RaceNo=" & CStr(m)
|
||||
|
||||
Dim chinese_race_link as String
|
||||
chinese_race_link = replace(race_link, "English","Chinese")
|
||||
driver.Get chinese_race_link
|
||||
|
||||
driver.FindElementsByTag ("td")
|
||||
' document.querySelectorAll('#racecardlist tbody tr')[2].textContent
|
||||
|
||||
Dim race_summary_content, race_summary_result As String
|
||||
' document.querySelectorAll('.raceCard div')[6].textContent.split(',').map(l => l.replace(/\n/g,'').trim()).filter(l => l.trim() != '')
|
||||
race_summary_content = "{ return document.querySelectorAll('.raceCard div')[8]?.innerHTML.replace(/<br>/g,', ').split(', ').join('|||') }"
|
||||
race_summary_result = driver.ExecuteScript(race_summary_content)
|
||||
|
||||
Dim course_name As String
|
||||
Dim course_length As String
|
||||
Dim course_class As String
|
||||
Dim course_condition As String
|
||||
Dim mark_range As String
|
||||
|
||||
course_name = driver.ExecuteScript("{return document.querySelectorAll('.raceCard div')[8]?.innerHTML.split(/<br>/g)[2].split(', ').reverse().slice(2).join(' ')}")
|
||||
course_length = driver.ExecuteScript("{return document.querySelectorAll('.raceCard div')[8]?.innerHTML.split(/<br>/g)[2].split(', ').reverse()[1]}")
|
||||
course_class = driver.ExecuteScript("{return document.querySelectorAll('.raceCard div')[8]?.innerHTML.split(/<br>/g)[3].split(', ').reverse()[0] }")
|
||||
course_condition = driver.ExecuteScript("{return document.querySelectorAll('.raceCard div')[8]?.innerHTML.split(/<br>/g)[2].split(', ').reverse()[0] }")
|
||||
mark_range = driver.ExecuteScript("{return document.querySelectorAll('.raceCard div')[8]?.innerHTML.split(/<br>/g)[3].split(', ').reverse()[1].split(': ')[1] }")
|
||||
|
||||
row_offset_start = row_offset
|
||||
|
||||
Dim actual_horse_count As Integer
|
||||
actual_horse_count = 0
|
||||
|
||||
For j = 0 To 30
|
||||
|
||||
Dim s_test, s_test_result As String
|
||||
s_test = "{ return document.querySelectorAll('#racecardlist tbody tr td')[" & (27) + j * 27 + 1 & "]?.textContent.trim()||'not found' }"
|
||||
s_test_result = driver.ExecuteScript(s_test)
|
||||
|
||||
If (s_test_result = "not found") Then
|
||||
|
||||
Else
|
||||
actual_horse_count = actual_horse_count + 1
|
||||
|
||||
Dim horse_id As String
|
||||
|
||||
Dim s_content, s_result As String
|
||||
'1 ???? --> Horse No.
|
||||
s_content = "{ return document.querySelectorAll('#racecardlist tbody tr td')[" & (27) + j * 27 + 1 & "].textContent.trim() }"
|
||||
s_result = driver.ExecuteScript(s_content)
|
||||
startCell.Offset(row_offset, 1).value = s_result
|
||||
|
||||
'2 6??? --> Last 6 Runs
|
||||
'3 ?? --> Colour
|
||||
'4 ?? --> Horse
|
||||
s_content = "{ return document.querySelectorAll('#racecardlist tbody tr td')[" & (27) + j * 27 + 4 & "].textContent.trim() }"
|
||||
s_result = driver.ExecuteScript(s_content)
|
||||
startCell.Offset(row_offset, 2).value = s_result
|
||||
|
||||
horse_id = driver.ExecuteScript("{ return document.querySelectorAll('#racecardlist tbody tr td')[" & (27) + j * 27 + 4 & "].querySelector('a').href.split('=')[1] }")
|
||||
startCell.Offset(row_offset, 400).value = horse_id
|
||||
|
||||
'5 ?? --> Brand No.
|
||||
s_content = "{ return document.querySelectorAll('#racecardlist tbody tr td')[" & (27) + j * 27 + 5 & "].textContent.trim() }"
|
||||
s_result = driver.ExecuteScript(s_content)
|
||||
startCell.Offset(row_offset, 0).value = s_result
|
||||
|
||||
'6 ?? --> Wt.
|
||||
s_content = "{ return document.querySelectorAll('#racecardlist tbody tr td')[" & (27) + j * 27 + 6 & "].textContent.trim() }"
|
||||
s_result = driver.ExecuteScript(s_content)
|
||||
startCell.Offset(row_offset, 7).value = s_result
|
||||
|
||||
'7 ?? --> Jockey
|
||||
s_content = "{ return document.querySelectorAll('#racecardlist tbody tr td')[" & (27) + j * 27 + 7 & "].textContent.trim() }"
|
||||
s_result = driver.ExecuteScript(s_content)
|
||||
startCell.Offset(row_offset, 3).value = s_result
|
||||
|
||||
'8 ???? --> Over Wt.
|
||||
'9 ?? --> Draw
|
||||
s_content = "{ return document.querySelectorAll('#racecardlist tbody tr td')[" & (27) + j * 27 + 9 & "].textContent.trim() }"
|
||||
s_result = driver.ExecuteScript(s_content)
|
||||
startCell.Offset(row_offset, 5).value = s_result
|
||||
|
||||
'10 ??? --> Trainer
|
||||
s_content = "{ return document.querySelectorAll('#racecardlist tbody tr td')[" & (27) + j * 27 + 10 & "].textContent.trim() }"
|
||||
s_result = driver.ExecuteScript(s_content)
|
||||
startCell.Offset(row_offset, 4).value = s_result
|
||||
|
||||
'11 ?? --> Rtg.
|
||||
s_content = "{ return document.querySelectorAll('#racecardlist tbody tr td')[" & (27) + j * 27 + 12 & "].textContent.trim() }"
|
||||
s_result = driver.ExecuteScript(s_content)
|
||||
startCell.Offset(row_offset, 8).value = s_result
|
||||
|
||||
'12 ??+/- --> Rtg.+/-
|
||||
'13 ???? --> Horse Wt. (Declaration)
|
||||
s_content = "{ return document.querySelectorAll('#racecardlist tbody tr td')[" & (27) + j * 27 + 13 & "].textContent.trim() }"
|
||||
s_result = driver.ExecuteScript(s_content)
|
||||
startCell.Offset(row_offset, 9).value = s_result
|
||||
|
||||
'14 ????+/- --> Wt.+/- (vs Declaration)
|
||||
'15 ???? --> Best Time
|
||||
'16 ?? --> Age
|
||||
s_content = "{ return document.querySelectorAll('#racecardlist tbody tr td')[" & (27) + j * 27 + 17 & "].textContent.trim() }"
|
||||
s_result = driver.ExecuteScript(s_content)
|
||||
startCell.Offset(row_offset, 6).value = s_result
|
||||
|
||||
'17 ???? --> WFA
|
||||
'18 ?? --> Sex
|
||||
s_content = "{ return document.querySelectorAll('#racecardlist tbody tr td')[" & (27) + j * 27 + 19 & "].textContent.trim() }"
|
||||
s_result = driver.ExecuteScript(s_content)
|
||||
startCell.Offset(row_offset, 10).value = s_result
|
||||
|
||||
'19 ???? --> Season Stakes
|
||||
'20 ?????? --> Priority
|
||||
'21 ?????? --> Days since Last Run
|
||||
s_content = "{ return document.querySelectorAll('#racecardlist tbody tr td')[" & (27) + j * 27 + 22 & "].textContent.trim() }"
|
||||
s_result = driver.ExecuteScript(s_content)
|
||||
startCell.Offset(row_offset, 12).value = s_result
|
||||
|
||||
'22 ?? --> Gear
|
||||
s_content = "{ return document.querySelectorAll('#racecardlist tbody tr td')[" & (27) + j * 27 + 23 & "].textContent.trim() }"
|
||||
s_result = driver.ExecuteScript(s_content)
|
||||
startCell.Offset(row_offset, 11).value = s_result
|
||||
|
||||
'23 ?? --> Owner
|
||||
'24 ?? --> Sire
|
||||
s_content = "{ return document.querySelectorAll('#racecardlist tbody tr td')[" & (27) + j * 27 + 25 & "].textContent.trim() }"
|
||||
s_result = driver.ExecuteScript(s_content)
|
||||
startCell.Offset(row_offset, 13).value = s_result
|
||||
|
||||
'25 ?? --> Dam
|
||||
s_content = "{ return document.querySelectorAll('#racecardlist tbody tr td')[" & (27) + j * 27 + 26 & "].textContent.trim() }"
|
||||
s_result = driver.ExecuteScript(s_content)
|
||||
startCell.Offset(row_offset, 14).value = s_result
|
||||
|
||||
'26 ???? --> Import Cat.
|
||||
|
||||
|
||||
startCell.Offset(row_offset, 15).value = Split(race_summary_result, "|||")(1)
|
||||
startCell.Offset(row_offset, 16).value = Split(race_summary_result, "|||")(3)
|
||||
startCell.Offset(row_offset, 17).value = course_length
|
||||
startCell.Offset(row_offset, 18).value = course_name
|
||||
startCell.Offset(row_offset, 19).value = course_class
|
||||
startCell.Offset(row_offset, 20).value = course_condition
|
||||
startCell.Offset(row_offset, 21).value = mark_range
|
||||
startCell.Offset(row_offset, 22).value = Split(Split(Split(race_summary_result, "|||")(0), " - ")(0), " ")(2)
|
||||
|
||||
|
||||
not_used = Horse_aspx.ScrapeHorse(driver1, startCell.Offset(row_offset, 400).value, CStr(row_offset))
|
||||
|
||||
not_used = TrackworkResult_aspx.Scrape(driver1, startCell.Offset(row_offset, 400).value, row_offset, s_date)
|
||||
|
||||
row_offset = row_offset + 1
|
||||
End If
|
||||
|
||||
Next j
|
||||
|
||||
'not_used = LocalResults_aspx.ScrapeLocalResults(driver1, s_date, CStr(m), row_offset_start, actual_horse_count)
|
||||
'not_used = DisplaySectionalTime_aspx.ScrapeDisplaySectionalTime(driver1, s_date, CStr(m), row_offset_start, actual_horse_count)
|
||||
|
||||
' Next m
|
||||
Next race_link
|
||||
|
||||
GoTo Done
|
||||
|
||||
ErrorHandler:
|
||||
MsgBox "Error: " & Err.Description
|
||||
|
||||
Done:
|
||||
driver.Quit
|
||||
driver1.Quit
|
||||
|
||||
Common.ResumeScreenUpdate
|
||||
|
||||
Common.TidySheet
|
||||
|
||||
End Sub
|
||||
|
||||
|
||||
|
||||
' write cell
|
||||
Sub writeCell(cell_addres As String, value As String)
|
||||
|
||||
End Sub
|
||||
|
||||
|
||||
Private Sub Take_ScreenShot_Desktop()
|
||||
Dim utils As New utils
|
||||
Dim driver As New ChromeDriver
|
||||
driver.Get "https://en.wikipedia.org/wiki/Main_Page"
|
||||
|
||||
Dim img As Object
|
||||
|
||||
'take a screenshot of the desktop
|
||||
Set img = utils.TakeScreenshot()
|
||||
|
||||
'save the image in the folder of the workbook
|
||||
img.SaveAs ThisWorkbook.Path & "\sc-desktop.png"
|
||||
|
||||
driver.Quit
|
||||
End Sub
|
||||
|
||||
|
||||
|
||||
|
||||
|
122
abc2022d/task1/ticket0002/TrackworkResult_aspx.bas
Normal file
122
abc2022d/task1/ticket0002/TrackworkResult_aspx.bas
Normal file
@@ -0,0 +1,122 @@
|
||||
Attribute VB_Name = "TrackworkResult_aspx"
|
||||
|
||||
Option Explicit
|
||||
|
||||
|
||||
Public Sub test()
|
||||
'horse_id = "HK_2022_H195"
|
||||
'row_offset = 0
|
||||
Dim horse_id As String
|
||||
Dim row_offset As String
|
||||
|
||||
|
||||
' Create a new instance of the WebDriver.
|
||||
Dim driver As New WebDriver
|
||||
|
||||
' Set the path to the WebDriver executable.
|
||||
driver.SetBinary "C:\Users\logic\AppData\Local\Chromium\Application\chrome.exe"
|
||||
|
||||
' Start Chrome.
|
||||
driver.Start "chrome"
|
||||
|
||||
|
||||
Dim not_use As String
|
||||
not_use = TrackworkResult_aspx.Scrape(driver, "HK_2022_H195", 0, "2024/04/20")
|
||||
|
||||
|
||||
driver.Quit
|
||||
|
||||
End Sub
|
||||
|
||||
Public Function Scrape(driver As WebDriver, horse_id As String, ByVal row_offset As Integer, ByVal s_date As String)
|
||||
|
||||
Dim script_content As String
|
||||
|
||||
' Create a new instance of the WebDriver.
|
||||
'Dim driver As New WebDriver
|
||||
|
||||
' Set the path to the WebDriver executable.
|
||||
'driver.SetBinary "C:\Users\logic\AppData\Local\Chromium\Application\chrome.exe"
|
||||
|
||||
' Start Chrome.
|
||||
'driver.Start "chrome"
|
||||
|
||||
' Navigate to a website.
|
||||
driver.Get "https://racing.hkjc.com/racing/information/English/Trackwork/TrackworkResult.aspx?HorseId=" & horse_id
|
||||
|
||||
' document.querySelectorAll('#racecardlist tbody tr')[2].textContent
|
||||
Dim i, j As Integer
|
||||
|
||||
|
||||
Dim startCell As Range
|
||||
Set startCell = Worksheets("Sheet1").Range("A3")
|
||||
|
||||
Dim all_row As String
|
||||
|
||||
script_content = "{" & _
|
||||
"list_e = [];" & _
|
||||
"document.querySelector('div.performance table').querySelectorAll('tr').forEach((r,i) => {" & _
|
||||
" if (i > 0) list_e.push(r.textContent.replace(/\n +/g,'___').slice(3,-3));" & _
|
||||
"});" & _
|
||||
"return list_e.join('|||');" & _
|
||||
"}"
|
||||
|
||||
all_row = driver.ExecuteScript(script_content)
|
||||
|
||||
Dim table_rows As Variant
|
||||
table_rows = Split(all_row, "|||")
|
||||
|
||||
For i = 0 To UBound(table_rows) - 1
|
||||
|
||||
Dim td_s As Variant
|
||||
|
||||
Dim event_date As String
|
||||
td_s = Split(table_rows(i), "___")
|
||||
event_date = td_s(0)
|
||||
|
||||
Dim event_person as String
|
||||
td_s = Split(table_rows(i), "___")
|
||||
event_person = td_s(3)
|
||||
|
||||
|
||||
Dim date_diff As Integer
|
||||
date_diff = DateDiff("d", Common.ParseDDMMYYYY(event_date), s_date)
|
||||
|
||||
If (date_diff <= 20) Then
|
||||
If (InStr(td_s(1), "Barrier Trial") > 0) Then
|
||||
startCell.Offset(row_offset, 24).value = "Y"
|
||||
If (startCell.Offset(row_offset, 25).value = "") Then
|
||||
startCell.Offset(row_offset, 25).value = event_date
|
||||
Else
|
||||
startCell.Offset(row_offset, 25).value = startCell.Offset(row_offset, 25).value & "," & event_date
|
||||
End If
|
||||
End If
|
||||
|
||||
|
||||
If (InStr(td_s(1), "Gallop") > 0) Then
|
||||
' Gallop by R.B. ?
|
||||
if (InStr(event_person, "R.B.") > 0) Then
|
||||
startCell.Offset(row_offset, 26).value = "Y"
|
||||
end if
|
||||
|
||||
If (startCell.Offset(row_offset, 27).value = "") Then
|
||||
startCell.Offset(row_offset, 27).value = event_date
|
||||
Else
|
||||
startCell.Offset(row_offset, 27).value = startCell.Offset(row_offset, 27).value & "," & event_date
|
||||
' Dim current_cell As Variant
|
||||
' Set current_cell = startCell.Offset(0, 27)
|
||||
' current_cell.Hyperlinks.Add Anchor:=current_cell, Address:="https://racing.hkjc.com/racing/information/Chinese/Horse/Horse.aspx?HorseId=" & horse_id
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
|
||||
Next
|
||||
|
||||
'driver.Quit
|
||||
|
||||
End Function
|
||||
|
||||
|
||||
|
||||
|
||||
|
5
abc2022d/task1/ticket0002/dev.bat
Normal file
5
abc2022d/task1/ticket0002/dev.bat
Normal file
@@ -0,0 +1,5 @@
|
||||
@REM start excel by yourself
|
||||
|
||||
@REM ./test.xlsm
|
||||
|
||||
xlwings vba edit --file ./main.xlsm
|
3
abc2022d/task1/ticket0002/gitUpdate.bat
Normal file
3
abc2022d/task1/ticket0002/gitUpdate.bat
Normal file
@@ -0,0 +1,3 @@
|
||||
git add .
|
||||
git commit -m"update ticket0002,"
|
||||
start git push
|
17
abc2022d/task1/ticket0002/history.md
Normal file
17
abc2022d/task1/ticket0002/history.md
Normal file
@@ -0,0 +1,17 @@
|
||||
# history
|
||||
|
||||
## ticket0001
|
||||
|
||||
### Q
|
||||
|
||||
Hello 你好, 關於之前揾你幫手寫個 VBA , 發現了有 error 想揾你 fix
|
||||
|
||||
以下圖第 6 場 4 號勤德威力為例,
|
||||
我剛 gen 左個 excel ,
|
||||
發現佢無試閘但 vba show 左佢有試閘同試閘日期,
|
||||
同埋佢快操日期亦錯,
|
||||
以及佢之前 ge 快操並沒有由副練去做,
|
||||
煩請更正,
|
||||
謝謝
|
||||
|
||||
### Drill
|
BIN
abc2022d/task1/ticket0002/main.xlsm
Normal file
BIN
abc2022d/task1/ticket0002/main.xlsm
Normal file
Binary file not shown.
1
abc2022d/task1/ticket0003/.gitignore
vendored
Normal file
1
abc2022d/task1/ticket0003/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
Chromium
|
5
abc2022d/task1/ticket0003/dev.bat
Normal file
5
abc2022d/task1/ticket0003/dev.bat
Normal file
@@ -0,0 +1,5 @@
|
||||
@REM start excel by yourself
|
||||
|
||||
@REM ./test.xlsm
|
||||
|
||||
xlwings vba edit --file ./main.xlsm
|
3
abc2022d/task1/ticket0003/gitUpdate.bat
Normal file
3
abc2022d/task1/ticket0003/gitUpdate.bat
Normal file
@@ -0,0 +1,3 @@
|
||||
git add .
|
||||
git commit -m"update ticket0002,"
|
||||
start git push
|
17
abc2022d/task1/ticket0003/history.md
Normal file
17
abc2022d/task1/ticket0003/history.md
Normal file
@@ -0,0 +1,17 @@
|
||||
# history
|
||||
|
||||
## ticket0001
|
||||
|
||||
### Q
|
||||
|
||||
Hello 你好, 關於之前揾你幫手寫個 VBA , 發現了有 error 想揾你 fix
|
||||
|
||||
以下圖第 6 場 4 號勤德威力為例,
|
||||
我剛 gen 左個 excel ,
|
||||
發現佢無試閘但 vba show 左佢有試閘同試閘日期,
|
||||
同埋佢快操日期亦錯,
|
||||
以及佢之前 ge 快操並沒有由副練去做,
|
||||
煩請更正,
|
||||
謝謝
|
||||
|
||||
### Drill
|
BIN
abc2022d/task1/ticket0003/main.xlsm
Normal file
BIN
abc2022d/task1/ticket0003/main.xlsm
Normal file
Binary file not shown.
1
abc2022d/task1/ticket0003/reset.bat
Normal file
1
abc2022d/task1/ticket0003/reset.bat
Normal file
@@ -0,0 +1 @@
|
||||
rm *.bas
|
10
abc2022d/task1/video/slice.bat
Normal file
10
abc2022d/task1/video/slice.bat
Normal file
@@ -0,0 +1,10 @@
|
||||
ffmpeg -i VirtualBoxVM_jYOelfdpoX.mp4 -ss 02:05 -to 16:59 output.mp4
|
||||
install dotnetfx35 and selenium basic
|
||||
|
||||
|
||||
# 安裝 dotnetfx35 and selenium basic
|
||||
ttps://youtu.be/3mTbo63exHE
|
||||
|
||||
# 點用
|
||||
ttps://filetransfer.io/data-package/gES49XH7#link
|
||||
https://youtu.be/Kft1vWFmDrE
|
9
abcdesiihh/docker-share/Dockerfile
Normal file
9
abcdesiihh/docker-share/Dockerfile
Normal file
@@ -0,0 +1,9 @@
|
||||
# CREDIT: https://github.com/shren207/nextjs-docker-compose
|
||||
# Dockerfile
|
||||
FROM node:18-buster
|
||||
|
||||
RUN mkdir -p /app/node_modules
|
||||
RUN chown 1000:1000 -R /app
|
||||
WORKDIR /app
|
||||
|
||||
USER 1000:1000
|
5
abcdesiihh/docker-share/app/entry.sh
Normal file
5
abcdesiihh/docker-share/app/entry.sh
Normal file
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
set -ex
|
||||
|
||||
npm i
|
||||
npm run start
|
2117
abcdesiihh/docker-share/app/package-lock.json
generated
Normal file
2117
abcdesiihh/docker-share/app/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
17
abcdesiihh/docker-share/app/package.json
Normal file
17
abcdesiihh/docker-share/app/package.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "app",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"start": "http-server --cors ./public"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"http-server": "^14.1.1",
|
||||
"serve": "^14.2.0"
|
||||
}
|
||||
}
|
37
abcdesiihh/docker-share/app/public/index.html
Normal file
37
abcdesiihh/docker-share/app/public/index.html
Normal file
@@ -0,0 +1,37 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<!-- Required meta tags -->
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
|
||||
<!-- Bootstrap CSS -->
|
||||
<link
|
||||
href="//cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css"
|
||||
rel="stylesheet"
|
||||
crossorigin="anonymous"
|
||||
/>
|
||||
|
||||
<title>abcdesiihh</title>
|
||||
</head>
|
||||
<body>
|
||||
<div style="
|
||||
display: flex; flex-direction: column;
|
||||
justify-content: center;align-items: center;">
|
||||
<div>
|
||||
<h2>helloworld demo</h2>
|
||||
<div>
|
||||
<div>helloworld demo</div>
|
||||
<a href="//www.google.com">www.google.com</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Optional JavaScript; choose one of the two! -->
|
||||
|
||||
<!-- Option 1: Bootstrap Bundle with Popper -->
|
||||
<script
|
||||
src="//cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
|
||||
crossorigin="anonymous"
|
||||
></script>
|
||||
</body>
|
||||
</html>
|
33
abcdesiihh/docker-share/docker-compose.yml
Normal file
33
abcdesiihh/docker-share/docker-compose.yml
Normal file
@@ -0,0 +1,33 @@
|
||||
# CREDIT: https://github.com/shren207/nextjs-docker-compose
|
||||
services:
|
||||
abcdesiihh_share:
|
||||
container_name: abcdesiihh_share
|
||||
build: .
|
||||
restart: always
|
||||
volumes:
|
||||
- ./app:/app
|
||||
- abcdesiihh_node_modules:/app/node_modules
|
||||
working_dir: /app
|
||||
# command: sleep infinity
|
||||
command: bash entry.sh
|
||||
ports:
|
||||
- 8080
|
||||
|
||||
labels:
|
||||
- "traefik.enable=true"
|
||||
- "traefik.http.routers.abcdesiihh-http.rule=Host(`abcdesiihh.louislabs.com`)"
|
||||
- "traefik.http.routers.abcdesiihh-http.entrypoints=web"
|
||||
- "traefik.http.routers.abcdesiihh-http.middlewares=abcdesiihh-https"
|
||||
- "traefik.http.middlewares.abcdesiihh-https.redirectscheme.scheme=https"
|
||||
- "traefik.http.routers.abcdesiihh.rule=Host(`abcdesiihh.louislabs.com`)"
|
||||
- "traefik.http.routers.abcdesiihh.entrypoints=websecure"
|
||||
- "traefik.http.routers.abcdesiihh.tls.certresolver=myresolver"
|
||||
- "traefik.http.services.abcdesiihh.loadbalancer.server.port=8080"
|
||||
|
||||
networks:
|
||||
default:
|
||||
external:
|
||||
name: traefik-proxy-network
|
||||
|
||||
volumes:
|
||||
abcdesiihh_node_modules:
|
14
abcdesiihh/docker-share/package.json
Normal file
14
abcdesiihh/docker-share/package.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "docker-helloworld",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"into_docker": "docker compose exec -it test bash",
|
||||
"docker_rebuild": "docker compose up -d"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC"
|
||||
}
|
9
abcdesiihh/docker-share/up.sh
Normal file
9
abcdesiihh/docker-share/up.sh
Normal file
@@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -ex
|
||||
|
||||
docker compose pull
|
||||
docker compose build
|
||||
docker compose kill
|
||||
docker compose down
|
||||
docker compose up -d
|
7
abcdesiihh/gitUpdate.bat
Normal file
7
abcdesiihh/gitUpdate.bat
Normal file
@@ -0,0 +1,7 @@
|
||||
git status .
|
||||
|
||||
@pause
|
||||
|
||||
git add .
|
||||
git commit -m"update abcdesiihh,"
|
||||
start git push
|
11
abcdesiihh/meta.md
Normal file
11
abcdesiihh/meta.md
Normal file
@@ -0,0 +1,11 @@
|
||||
---
|
||||
tags: [pending]
|
||||
---
|
||||
|
||||
# abcdesiihh
|
||||
|
||||
not done
|
||||
|
||||
quotation HKD300 ~ HKD500
|
||||
|
||||
(https://www.carousell.com.hk/archive/1671093474/)
|
14
abcdesiihh/package.json
Normal file
14
abcdesiihh/package.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"name": "abcdesiihh",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"gitUpdate": "git add . && git commit -m\"update abcdesiihh,\"",
|
||||
"watch-bs": "npx browser-sync start -h 0.0.0.0 --proxy 'localhost:32768' --files \"**/app\""
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC"
|
||||
}
|
Reference in New Issue
Block a user