'login authentication and download multiple files using python

Im trying to download several files from a website. The link for each file is different and are stored in a txt file. To download the file user has to login. However, there are over 10000 files which I am trying to download.

Is there any better way to provide login credentials so that, authentication is done only once and files are iteratively downloaded as given in the code below.

import wget
# import requests
f = open("datalinks.txt", "r")
lnks = f.readlines()

for eachlink in lnks:
    if '.h5' in eachlink:
        file_url = eachlink
        wget.download(file_url)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source