-
Notifications
You must be signed in to change notification settings - Fork 0
/
websiteparser.py
31 lines (25 loc) · 992 Bytes
/
websiteparser.py
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
from bs4 import BeautifulSoup
import requests
import json
import numpy as np
base = "https://www.chloeting.com"
url = base + '/program/2021/summer-shred-challenge.html'
page = requests.get(url).text
soup = BeautifulSoup(page, "html.parser")
splitstr = "https://youtu.be/"
data = []
for div in soup.findAll('div', attrs={"class" : "cal-entry"}):
dayString = div.find('div', attrs={"class" : "info"}).find('p').text.strip()
videos = div.find('div', attrs={"class": "videos"})
vids = []
thumbs = []
for a in videos.findAll('a',href=True):
link = a['href'].strip()
youtube_id = link.split(splitstr)[1]
vids.append(youtube_id)
thumb = a.find("img")['src']
thumbs.append(base+thumb)
watched = [False] * len(vids)
data.append({"name" : dayString, "videos" : {"id" : vids, "thumbnails" : thumbs, "watched" : watched}, "watched" : False})
with open('./playlist-tracker/src/data.json', 'w') as f:
json.dump(data, f)