import re
import json
import requests
from textwrap import shorten
url = "https://www.coursera.org/specializations/digital-manufacturing-design-technology#courses"
html_doc = requests.get(url).text
data = json.loads(
re.search(r"window.__APOLLO_STATE__ = (.*});", html_doc).group(1)
)
please explain what the group() function does and what does its arguements signify?(1/2/3 etc..) what is APOLLO_STATE ??
uncomment to print all data:
print(json.dumps(data, indent=4))
i = 1
for k, v in data.items():
if "SDPCourse:" in k and "." not in k:
print(
"{:<3} {:<8} {:<60} {}".format(
i,
v["averageInstructorRating"],
v["name"],
shorten(v["description"], 40),
)
)
i += 1
Aucun commentaire:
Enregistrer un commentaire