---
# System prepended metadata

title: 運彩爬蟲資訊
tags: [LINEBOT]

---

# 運彩爬蟲資訊
###### tags: `LINEBOT`
[TOC]
## 目標網頁

若想要直接從運彩官網爬取相對繁雜。
由於賠率運動數據等都是即時更新，因此猜測會有個封包傳送至運彩網頁，而從網頁內找到了此API資訊。

2020年，API網址如下

```
https://www.sportslottery.com.tw/api/services/app/LiveGames/GetLiveOnAndRegister?isContainRegister=false
```

2021年，有天測試突然一直出現錯誤，後來發現是運彩官方的API改了，目前這個才能使用。
```
https://blob.sportslottery.com.tw/apidata/Live/On.json
```

## ＡＰＩ分析

### 2020

**2020年API內容如下**

#### 沒有場中投注比賽
```json=
{"result":{"liveOn":
[],"registerAll4Show":null},"targetUrl":null,"success":tr
ue,"error":null,"unAuthorizedRequest":false,"__abp":true}
```

#### 有場中投注的比賽

```json=
{"result":{"liveOn":
[{"id":256685,"no":2530,"kdt":1606903200000,"si":444,"cn"
:["韓國","Korea Republic"],"li":12760,"ln":["南韓V聯
賽","Korea Republic V-League"],"atn":["韓國電力公社","Suwon 
Kepco"],"htn":["現代資本天行者","Cheonan Skywalkers"],"ms":
[{"id":1,"no":1,"cs":
[[{"id":402,"o":"1.08","p":1,"h":null,"l":false},
{"id":400,"o":"4.25","p":3,"h":null,"l":false}]],"m":1,"m
a":8},{"id":6,"no":1,"cs":
[[{"id":661,"o":"1.00","p":1,"h":null,"l":true},
{"id":619,"o":"1.00","p":3,"h":null,"l":true}],
[{"id":654,"o":"1.60","p":1,"h":null,"l":false},
{"id":625,"o":"1.00","p":3,"h":null,"l":true}],
[{"id":648,"o":"3.45","p":1,"h":null,"l":false},
{"id":630,"o":"4.30","p":3,"h":null,"l":false}]],"m":1,"m
a":8}],"as":
{"1":25,"2":19,"3":25,"4":13,"5":-1,"6":-1,"7":-1,"8":-1,
"9":-1,"10":-1},"hs":
{"1":16,"2":25,"3":21,"4":13,"5":-1,"6":-1,"7":-1,"8":-1,
"9":-1,"10":-1},"gp":
{"1":2,"2":2,"3":2,"4":1,"5":0,"6":0,"7":0,"8":0,"9":0,"1
0":0},"gi":4,"ed":"
{\"Serve\":\"2\"}","lv":true,"l":false,"mi":24000869}],"r
egisterAll4Show":null},"targetUrl":null,"success":true,"e
rror":null,"unAuthorizedRequest":false,"__abp":true}
```

### 2021

**2021年更新之後的內容如下，有稍微改動而已。**

#### 沒有場中投注比賽
```json=
[]
```

#### 有場中投注比賽

```json=
[{"id":268495,"no":712,"kdt":1614096000000,"si":441,"cn"
:["土耳其","Turkey"],"li":13586,"ln":["土耳其甲級聯賽","1. 
Lig"],"atn":["阿特諾度","Altinordu FK"],"htn":["阿勒泰體
育","Altay Izmir"],"ms":[{"id":1,"no":1,"cs":
[[{"id":402,"o":"15.00","p":1,"h":null,"l":false},
{"id":401,"o":"4.50","p":2,"h":null,"l":false},
{"id":400,"o":"1.10","p":3,"h":null,"l":false}]],"m":1,"
ma":8},{"id":3,"no":1,"cs":
[[{"id":472,"o":"2.10","p":1,"h":2.500,"l":false},
{"id":471,"o":"1.48","p":3,"h":2.500,"l":false}],
[{"id":470,"o":"1.18","p":1,"h":1.500,"l":false},
{"id":469,"o":"3.35","p":3,"h":1.500,"l":false}],
[{"id":474,"o":"4.75","p":1,"h":3.500,"l":false},
{"id":473,"o":"1.05","p":3,"h":3.500,"l":false}]],"m":1,
"ma":8},{"id":4,"no":2,"cs":
[[{"id":549,"o":"1.00","p":1,"h":null,"l":true},
{"id":550,"o":"3.35","p":2,"h":null,"l":false},
{"id":551,"o":"2.25","p":3,"h":null,"l":false}],
[{"id":552,"o":"3.30","p":1,"h":null,"l":false},
{"id":553,"o":"7.00","p":2,"h":null,"l":false},
{"id":554,"o":"1.00","p":3,"h":null,"l":true}]],"m":1,"m
a":8},{"id":4,"no":3,"cs":
[[{"id":567,"o":"1.55","p":1,"h":null,"l":false},
{"id":568,"o":"1.90","p":2,"h":null,"l":false},
{"id":569,"o":"5.00","p":3,"h":null,"l":false}],
[{"id":570,"o":"1.00","p":1,"h":null,"l":true}]],"m":1,"
ma":8},{"id":4,"no":4,"cs":
[[{"id":563,"o":"1.00","p":1,"h":null,"l":true},
{"id":564,"o":"2.00","p":2,"h":null,"l":false},
{"id":565,"o":"1.80","p":3,"h":null,"l":false}],
[{"id":566,"o":"3.05","p":1,"h":null,"l":false}]],"m":1,
"ma":8},{"id":5,"no":1,"cs":
[[{"id":597,"o":"1.68","p":1,"h":null,"l":false},
{"id":598,"o":"1.82","p":3,"h":null,"l":false}]],"m":1,"
ma":8},{"id":7,"no":1,"cs":
[[{"id":405,"o":"3.46","p":4,"h":null,"l":true},
{"id":404,"o":"1.02","p":5,"h":null,"l":true},
{"id":403,"o":"1.00","p":6,"h":null,"l":true}]],"m":1,"m
a":8},{"id":9,"no":1,"cs":
[[{"id":609,"o":"2.60","p":1,"h":null,"l":false},
{"id":608,"o":"3.35","p":2,"h":null,"l":false},
{"id":607,"o":"1.75","p":3,"h":null,"l":false}]],"m":1,"
ma":8},{"id":16,"no":4,"cs":
[[{"id":414,"o":"3.50","p":1,"h":null,"l":false},
{"id":413,"o":"2.25","p":2,"h":null,"l":false},
{"id":412,"o":"2.15","p":3,"h":null,"l":false}]],"m":1,"
ma":8},{"id":17,"no":2,"cs":
[[{"id":417,"o":"1.37","p":1,"h":null,"l":true},
{"id":416,"o":"1.33","p":2,"h":null,"l":true},
{"id":415,"o":"1.10","p":3,"h":null,"l":true}]],"m":1,"m
a":8}],"as":
{"1":0,"2":-1,"3":-1,"4":-1,"5":-1,"6":-1,"7":-1,"8":-1,
"9":-1,"10":-1},"hs":
{"1":1,"2":-1,"3":-1,"4":-1,"5":-1,"6":-1,"7":-1,"8":-1,
"9":-1,"10":-1},"gp":
{"1":2,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"
10":0},"gi":1,"ed":"
{\"AllRemainingTime\":\"45\"}","lv":true,"l":false,"mi":
23312067}]
```

### API 說明

| KEY |  Value   |
|:---:|:--------:|
| si  |   球種   |
| cn  |   國家   |
| ln  | 比賽名稱 |
| atn | 客隊名稱 |
| htn | 主隊名稱 |
| ms  |   賠率   |
| as  | 客隊分數 |
| hs  | 主隊分數 |
| lv  |   動畫   |

因為每個球種的需要的資訊不一樣，因此可以先從球種去分類，之後也會比較好規劃個別顯示的畫面。

| 代號 | 球種        |
| ---- | ----------- |
| 441  | Soccer      |
| 442  | Baseketball |
| 443  | Baseball    |
| 444  | Volleyball  |
| 445  | Tennis      |


### 動畫

運彩有些比賽會有動畫顯示比賽情況，因此可先判定該場次是否有提供動畫。
若有動畫可以從==mi==獲取ID，提供以下網址顯示動畫。
```
https://h2h.sportslottery.com.tw/sportradar/zht/h2h.html?matchID=24422300
```