To download the mp4
videos with requests
, set Referer
HTTP header:
import requests
from bs4 import BeautifulSoup
url = "https://drswamyplabvideo.com"
headers = {"Referer": "https://drswamyplabvideo.com/"}
soup = BeautifulSoup(requests.get(url).content, "html.parser")
for v in soup.select("video source[src]"):
print("Downloading {}".format(v["src"]))
with open(v["src"].split("/")[-1].strip(), "wb") as f_out:
f_out.write(requests.get(v["src"].strip(), headers=headers).content)
Prints:
Downloading https://drswamyplabvideo.com/videos/Demo video.mp4
Downloading https://drswamyplabvideo.com/videos/CNS Day 1 by Nosheen Part 1.mp4
Downloading https://drswamyplabvideo.com/videos/CNS Part 5.mp4
Downloading https://drswamyplabvideo.com/videos/Lady with fracture wrist Talk to son.mp4
and saves the videos.