-
Notifications
You must be signed in to change notification settings - Fork 0
/
chanwalls.py
29 lines (21 loc) · 980 Bytes
/
chanwalls.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import os
import requests
import urllib.request
from bs4 import BeautifulSoup
# takes the url for the thread you wanted to download the images from
# make sure that the url has the protocol thingy as the prefix
thread_url = input("Enter the url for the thread: ")
response = requests.get(thread_url)
soup = BeautifulSoup(response.text, "html.parser")
# thread_name used to create folder for storing the corresponding images
thread_name = soup.find('span', {'class': 'subject'}).string
images = soup.findAll('a', {'class': 'fileThumb'})
#prints total number of images to be downloaded
print("No of images to be downloaded: ", len(images))
# creates the folder
os.mkdir(thread_name)
for index, img in enumerate(images):
# gets image name from the last part of href
img_name = img.get('href').split('/')
urllib.request.urlretrieve('https:'+img.get('href'), os.path.join(thread_name, img_name[-1]))
print("Image {0} downloaded".format(index))