I wrote a python script to download images from tinyboard/vichan imageboards.
It works on every imageboard I try except 8ch, which gives me a 403 forbidden error. I tried changing my user agent within the script (perhaps unsuccessfully), but still 403. What gives?
#!/usr/bin/env python3
import argparse, bs4, os, urllib.request, urllib.parse
parser = argparse.ArgumentParser()
parser.add_argument("url", help="Link to thread")
parser.add_argument("-d", help="Directory to download to")
args = parser.parse_args()
if args.d:
if not os.path.exists(args.d):
os.makedirs(args.d)
os.chdir(args.d)
soup = bs4.BeautifulSoup(urllib.request.urlopen(args.url))
domain = urllib.parse.urlparse(args.url).netloc
http = urllib.parse.urlparse(args.url).scheme + "://"
for link in soup.find_all("p", class_="fileinfo"):
image = http + domain + link.next_sibling.get("href")
filename = image.rsplit("/", 1)[1]
if not os.path.exists(filename):
urllib.request.urlretrieve(image, filename