Created
August 15, 2018 21:13
-
-
Save LS80/510719fd59fdfc0fee751afd6b2ea315 to your computer and use it in GitHub Desktop.
Spurs TV Videos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import json | |
import pprint | |
from collections import namedtuple | |
import requests | |
pp = pprint.PrettyPrinter() | |
Video = namedtuple('Video', 'entry_id caption thumbnail') | |
VIDEO_DATA_RE = ( | |
r"React\.createElement\(Components\.TrendingGridModule, (.*?)\)" | |
r", document.getElementById\(" | |
) | |
URL = "https://www.tottenhamhotspur.com/spurs-tv/" | |
def videos(): | |
data = re.search(VIDEO_DATA_RE, requests.get(URL).text).group(1) | |
videos = json.loads(data)['data']['modules'] | |
for video in videos: | |
video_data = video['data'] | |
yield Video(video_data['entryId'], video_data['caption'], video_data['thumbnail']['smallUrl']) | |
pp.pprint(list(videos())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment