download web DirAuthor: Dave Date: 07.07.17 - 10:55am quick python script to download all files of a certain extension from a html web directory to a local folder. make sure you have beautiful soup installed: pip install beautifulsoup4 todo: create folder if it doesnt exist from urllib2 import urlopen from bs4 import BeautifulSoup webDir = 'https://indy.fulgan.com/SSL/' localDir = 'c:\\webdl2\\' urlpath =urlopen(webDir) html = urlpath.read().decode('utf-8') soup = BeautifulSoup(html,"html.parser") links = soup.find_all('a') filelist = [] for tag in links: link = tag.get('href',None) if link is not None and link.find('.zip') != -1: #print link filelist.append(link) print('%d files to dl...' % len(filelist) ) for i, filename in enumerate(filelist): remotefile = urlopen(webDir + filename) localfile = open(localDir + filename,'wb') localfile.write(remotefile.read()) localfile.close() remotefile.close() print('%d/%d' % (i , len(filelist))) print('done') Comments: (0) |
About Me More Blogs Main Site
|
||||||||||||||||||||||