在Python中使用 pycricbuzz 库
Pycricbuzz是一个Python库,可用于获取最近和现场比赛的实时比分、评论和完整记分卡。
如果您想了解该库是如何开发的,可以观看视频:https://youtu.be/OQqYbC1BKxw
安装:在终端中运行以下pip命令。
pip install pycricbuzz
首先,我们需要创建一个Cricbuzz()对象以进行进一步的操作。
Python3
# importing the modules
from pycricbuzz import Cricbuzz
# creating a Cricbuzz object
c = Cricbuzz()
Python3
# importing the modules
from pycricbuzz import Cricbuzz
# creating a Cricbuzz object
c = Cricbuzz()
# displaying all the matches
print(c.matches())
Python3
# importing the modules
from pycricbuzz import Cricbuzz
import json
# creating a Cricbuzz object
c = Cricbuzz()
# displaying all the matches
print(json.dumps(c.matches(), indent = 4))
Python3
# importing the modules
from pycricbuzz import Cricbuzz
import json
# creating a Cricbuzz object
c = Cricbuzz()
# displaying the match information
print(json.dumps(c.matchinfo('30560'), indent = 4))
Python3
# importing the modules
from pycricbuzz import Cricbuzz
import json
# creating a Cricbuzz object
c = Cricbuzz()
# displaying the match score
print(json.dumps(c.livescore('30505'), indent = 4))
Python3
# importing the modules
from pycricbuzz import Cricbuzz
import json
# creating a Cricbuzz object
c = Cricbuzz()
# displaying the match score
print(json.dumps(c.scorecard('30505'), indent = 4))
Python3
# importing the modules
from pycricbuzz import Cricbuzz
import json
# creating a Cricbuzz object
c = Cricbuzz()
# displaying the match commentary
print(json.dumps(c.commentary('30505'), indent = 4))
获取 Cricbuzz 提供的所有匹配项
我们使用matches()方法来获取所有实时的、即将到来的和最近完成的比赛。每个匹配项都有一个与之关联的 ID。
蟒蛇3
# importing the modules
from pycricbuzz import Cricbuzz
# creating a Cricbuzz object
c = Cricbuzz()
# displaying all the matches
print(c.matches())
输出:
默认情况下的输出很难阅读。我们可以使用 JSON 使输出匹配更易读。
蟒蛇3
# importing the modules
from pycricbuzz import Cricbuzz
import json
# creating a Cricbuzz object
c = Cricbuzz()
# displaying all the matches
print(json.dumps(c.matches(), indent = 4))
输出:
获取特定比赛的信息
我们可以使用matchinfo()方法来获取特定匹配的信息。我们必须在此方法中传递匹配 ID。
蟒蛇3
# importing the modules
from pycricbuzz import Cricbuzz
import json
# creating a Cricbuzz object
c = Cricbuzz()
# displaying the match information
print(json.dumps(c.matchinfo('30560'), indent = 4))
输出:
获取比赛的实时比分
我们可以使用livecore()方法获取现场比赛的比分。仅将其用于现场比赛。
蟒蛇3
# importing the modules
from pycricbuzz import Cricbuzz
import json
# creating a Cricbuzz object
c = Cricbuzz()
# displaying the match score
print(json.dumps(c.livescore('30505'), indent = 4))
输出:
获取比赛的记分卡
我们可以使用scorecard()方法获取比赛的记分卡。在此方法中传递目标匹配的匹配 id。
蟒蛇3
# importing the modules
from pycricbuzz import Cricbuzz
import json
# creating a Cricbuzz object
c = Cricbuzz()
# displaying the match score
print(json.dumps(c.scorecard('30505'), indent = 4))
输出:
获取比赛评论
我们可以使用commentary()方法获取特定比赛的评论。在此方法中传递匹配 ID。
蟒蛇3
# importing the modules
from pycricbuzz import Cricbuzz
import json
# creating a Cricbuzz object
c = Cricbuzz()
# displaying the match commentary
print(json.dumps(c.commentary('30505'), indent = 4))
输出: