Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from bs4 import BeautifulSoup
- import urllib2
- import os
- url = raw_input('Thread URL: ')
- subfolder = raw_input('Subfolder name: ')
- if len(subfolder) > 0:
- path = os.path.abspath('./4chdl/' + subfolder)
- elif len(subfolder) == 0:
- path = os.path.abspath('./4chdl')
- if not os.path.exists(path):
- os.makedirs(path)
- page = BeautifulSoup(urllib2.urlopen(url))
- for link in page.findAll('a', attrs = {'class' : 'fileThumb'}):
- href = 'http://' + link['href'][2:]
- res = urllib2.urlopen(href)
- data = res.read()
- name = href[-17:]
- filename = os.path.join(path, name)
- if os.path.exists(filename):
- print '%s already exists.' % name
- else:
- f = open(filename, 'wb')
- f.write(data)
- f.close()
- print '%s downloaded' % name
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement