Mar-07-2022, 10:11 AM
You most look at what you first function return.
The test is simple paste into browser as see what happens.
Here is fix for your first function then can try to figure how to download.
>>> get_video_links()[0] 'https://file-examples.com/index.php/sample-video-files/sample-mp4-files/https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_480_1_5MG.mp4'Dos that look like working download link?
The test is simple paste into browser as see what happens.
Here is fix for your first function then can try to figure how to download.
import requests from bs4 import BeautifulSoup def video_links(video_url): response = requests.get(video_url) soup = BeautifulSoup(response.content, 'html5lib') for url_link in soup.find_all(class_="text-right file-link"): yield url_link.a.get('href', 'Something went wrong') def download_video_series(video_links): pass if __name__ == '__main__': video_url = "https://file-examples.com/index.php/sample-video-files/sample-mp4-files/" for link in video_links(video_url): print(link)
Output:https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_480_1_5MG.mp4
https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_640_3MG.mp4
https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_1280_10MG.mp4
https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_1920_18MG.mp4
Also don't use the old sting formatting(%s
) anymore.print("Downloading file:%s" % file_name) # f-string print(f"Downloading file: {file_name}")