-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
39 lines (32 loc) · 1.01 KB
/
Copy pathserver.py
File metadata and controls
39 lines (32 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from bs4 import BeautifulSoup
import requests
from flask import *
import json
from flask_cors import CORS
app = Flask(__name__)
CORS(app)
@app.route("/", methods=["GET"])
def home_page():
data_set = {"Page": "Homepage of Cricbuzz Basic API", "Status": "Success!"}
json_dump = json.dumps(data_set)
return json_dump
@app.route("/basic", methods=["GET"])
def basic_details():
url = "https://www.cricbuzz.com"
html_text = requests.get(url).text
soup = BeautifulSoup(html_text, "lxml")
gamesList = soup.findAll("li", class_="cb-view-all-ga cb-match-card cb-bg-white")
games = []
for game in gamesList:
gameText = game.text
arr = gameText.split(" • ")
match = arr[0].replace(" ", "")
leftArr = arr[1].split(" ")
title = leftArr[0]
score = leftArr[1]
data_set = {"Match": match, "Title": title, "Score": score}
games.append(data_set)
json_dump = json.dumps(games)
return json_dump
if __name__ == "__main__":
app.run()