How to download files using Wget and python

In this session, I'll attempt to cover Wget and use python to fetch the data with help of Command line which enhances your capacity for flawless performance in interview questions and practical tests. If you are interested in DevOps and Python Engineer; I will recommend that you read this article carefully.

Wget

 Is a program

 Download files from the internet

 Used TCP Protocal

 Support HTTP, HTTPS, FTP, FTPS 

Why Wget?

It is a network command line tool that you can download the file from the server . Most used in RestAPI and deal with unstable network or slow network connections. Wget will continue to attempt until the file is downloaded.

Installation and basic commands

I am used to window 10 OS and will show you every command step by step via window terminal.

  1. First we need to import the wget library by use of pip install wget command.
  2. Command python -m wget [options] <URL.

options 

-o –output FILE|DIR output filename or directory

Run the below command in the terminal

D:\KnowledgeHunt> python -m wget --version

wget.py 3.2

python -m wget -o-datas  https://jsonplaceholder.typicode.com/posts?_limit=2

using the -o option to specify a new name of file and we used wget to send a GET request to jsonplaceholder.typicode.com get json details which is stored in -datas file. 

Run the command on terminal

D:\KnowledgeHunt> python -m wget -o-datas https://jsonplaceholder.typicode.com/posts?_limit=2

Result look like as below

100% [..................................................................................] 600 / 600

Saved under -datas




[

  {

    "userId": 1,

    "id": 1,

    "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",

    "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"

  },

  {

    "userId": 1,

    "id": 2,

    "title": "qui est esse",

    "body": "est rerum tempore vitae\nsequi sint nihil reprehenderit dolor beatae ea dolores neque\nfugiat blanditiis voluptate porro vel nihil molestiae ut reiciendis\nqui aperiam non debitis possimus qui neque nisi nulla"

  }

]

Similar to that, you can download any type of file, including jpg, mp4, and others.







Comments