Skip to content

Instantly share code, notes, and snippets.

@LS80
Created August 15, 2018 21:13
Show Gist options
  • Save LS80/510719fd59fdfc0fee751afd6b2ea315 to your computer and use it in GitHub Desktop.
Save LS80/510719fd59fdfc0fee751afd6b2ea315 to your computer and use it in GitHub Desktop.
Spurs TV Videos
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