We’ll talk about how to use Python to download Facebook videos with a page URL.
You may have seen some amazing videos that you want to save for later. Good news: if you like Python, it’s easy to download the Facebook video with Python.
Here’s what you should do
Import Necessary Modules
- Sys– The sys module in Python provides different functions and variables used to manipulate the python runtime environment. It allows easy access to variables and functions that interact with the interpreter.
- OS:- The OS module in Python provides easy access to interact with the operating system. OS comes under Python’s standard utility module.
- Requests:- The request module in Python allows you to send HTTP requests. The HTTP request returns a response object with all the response data.
- Wget:- In Python’s wget download utility module, you can save files from the internet server.
How to Download Facebook Videos With Pageurl Using Python?
Step 1: Import Module.
import sys import os import requests as r import wget filedir = os.path.join('C:/Users/varsh/Downloads') try: LINK = "https://www.facebook.com/peopleareawesome/videos/637730157348346/" #url of video to be downloaded html = r.get(LINK) except r.ConnectionError as e: print("Error in connecting") except r.Timeout as e: print("Timeout") except r.RequestException as e: print("Invalid URL") except (KeyboardInterrupt, SystemExit): print("System has quit") sys.exit(1) except TypeError: print("Video seems to be private ") else: print("\n") print("Video Quality:Normal " ) print("[+] Starting Download") wget.download(LINK,filedir) print("\n") print("Video downloaded")
Step 2: Get the URL that you want to download.
Step 3: Save the content with the name. Check the downloaded file in the directory.
You can easily download the Facebook video with the code by pasting the URL into the link section. You can also pick where you want the file to be saved. To do this, tell the download () method where the area is.
Also, you can find the file that you downloaded in the directory. You can also download the urllib library and use that instead of wget. The library’s name will be urllib (URL, filepath). Let me know if you have any more questions in the section below.
You can also check out this helpful YouTube video.