import os from mwclient import Site from pprint import pprint site = Site(host='hub.xpub.nl/sandbox', path='/itchwiki/') wd = os.path.abspath('.') # working directory imgdir = os.path.join(wd, 'images') os.makedirs(imgdir, exist_ok=True) # create images/ dir with open(os.path.join(wd, 'login.txt'), 'r') as login: # read login user & pwd loginlines = login.read() user, pwd = loginlines.split('\n') user.replace('\n', '') pwd.replace('\n', '') site.login(username=user, password=pwd) # login to wiki print(site) for n , img in enumerate(site.allimages()): if n < 3: print(img) # print(img.__dict__) # info contained in each img object # important img info to dictionary img_dict = { 'name': img.name, 'filename': img.page_title, 'timestamp': img.imageinfo['timestamp'], 'url': img.imageinfo['url'], 'urldesc': img.imageinfo['descriptionshorturl'], } pprint(img_dict) img_fn = os.path.join(imgdir, img_dict['filename']) with open(img_fn, 'wb') as img_file: img.download(destination=img_file)