-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtedTalkDownloader.py
More file actions
40 lines (20 loc) · 948 Bytes
/
tedTalkDownloader.py
File metadata and controls
40 lines (20 loc) · 948 Bytes
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
40
import requests #getting content of the TED Talk page
from bs4 import BeautifulSoup #web scraping
import re #Regular Expression pattern matching
from urllib.request import urlretrieve #downloading mp4
url = "https://www.ted.com/talks/talithia_williams_own_your_body_s_data"
r = requests.get(url)
print("Download about to start")
soup = BeautifulSoup(r.content, features="lxml")
for val in soup.findAll("script"):
if(re.search("talkPage.init",str(val))) is not None:
result = str(val)
result_mp4 = re.search("(?P<url>https?://[^\s]+)(mp4)", result).group("url")
mp4_url = result_mp4.split('"')[0]
print("Downloading video from ..... " + mp4_url)
file_name = mp4_url.split("/")[len(mp4_url.split("/"))-1].split('?')[0]
print("Storing video in ..... " + file_name)
r = requests.get(mp4_url)
with open(file_name,'wb') as f:
f.write(r.content)
print("Download Process finished")