
Version 0.2.5
Sali贸 el nuevo corto de Pixar
https://youtu.be/A4-G7YpSFb4
El ultimo
Bien, ya lo encontr茅. Son unos afiches que pegaron por aqu铆 para cuando se estren贸 la pel铆cula.
>>92250
a la mierda, 驴salsa del artista?
>>38666
Algo as铆:
# -*- coding: utf-8 -*-
import sys
import os
import re
import urllib.request
import urllib.parse
def getthreadinfo(url):
# https://www.hispachan.org/xx/res/xx.html
r = urllib.parse.urlparse(url.lower())
s = r.netloc
if not (s.startswith("www.hispachan.org") or s.startswith("hispachan.org")):
return None
f = r.path.split("/")
if len(f) != 4:
return None
if f[2] != "res":
return None
board = f[1]
thread = f[3].split(".")[0]
if not (board or thread):
return None
return (board, thread)
def getimglist(url):
imglist = []
opener = urllib.request.build_opener()
opener.addheaders = [
('User-agent', 'Mozilla/5.0')
]
try:
f = opener.open(url)
b = f.read()
except:
raise
f.close()
i = 0
while 1:
try:
i = b.index(b"", i + 1)
except ValueError:
break
imglist.append(i)
cname = re.compile(b'href="[^=]+(hispachan.org.+.src.([0-9]+.+))"')
rname = re.compile(b'<.+class="nombrefile">.?\s+(.+)<.+>')
for i in range(len(imglist)):
name1 = cname.search(b, imglist[i], imglist[i]+1024)
name2 = rname.search(b, imglist[i], imglist[i]+1024)
r = [None, None, None]
if name1:
r[0] = name1.group(1).decode("utf-8")
r[1] = name1.group(2).decode("utf-8")
if name2:
r[2] = name2.group(1).decode("utf-8")
imglist[i] = r
return imglist
def saveimg(url, path, owrite):
opener = urllib.request.build_opener()
opener.addheaders = [
('User-agent', 'Mozilla/5.0')
]
try:
f = opener.open(url)
b = f.read()
except:
return False
# si el archivo existe intentamos con un nuevo nombre
if not owrite and os.path.isfile(path):
fnme, fext = os.path.splitext(path)
i = 1
while os.path.isfile(path):
path = fnme + "(" + str(i) +")" + fext
i += 1
try:
fh = open(path, "wb")
fh.write(b)
fh.close()
except:
return False
return True
def saveimages(imglist, dpath, owrite):
path = os.path.abspath(dpath)
try:
os.makedirs(path)
except FileExistsError:
pass
print("Descargando {} imagenes en \n[{}]".format(len(imglist), path))
f = 0
i = len(imglist)
for img in imglist:
if not img[0]:
continue
link = "https://"; + img[0]
name = img[1]
if img[2]:
name = img[2]
name = os.path.join(path, name)
if not saveimg(link, name, owrite):
print("[FAIL]", end="")
f += 1
print(link)
print("Terminado: imagenes descargadas {}, errores {}".format(i - f, f))
usage = """
Uso: thisscript.py [opciones][ ]
Opciones:
-no-subfolder Omite la creacion de una subcarpeta para las imagenes.
-overwrite Sobrescribe las imagenes con el mismo nombre.
"""
def showusage():
print(usage)
exit()
if name == "main":
if len(sys.argv) < 2:
showusage()
sys.argv.pop(0)
args = sys.argv
# esto no es correcto, de este modo las opciones pueden ir en cualquier
# posicion
subfolder = True
overwrite = False
try:
i = args.index("-no-subfolder")
args.pop(i)
subfolder = not subfolder
except ValueError:
pass
try:
i = args.index("-overwrite")
args.pop(i)
overwrite = not overwrite
except ValueError:
pass
if not args or args.count("-overwrite") or args.count("-no-subfolder"):
showusage()
r = getthreadinfo(args.pop(0))
if r:
url = "https://hispachan.org/{}/res/{}.html".format(r[0], r[1])
try:
imglist = getimglist(url)
if not imglist:
print("Error: ninguna imagen para descargar")
exit()
dst = os.getcwd()
if sys.argv:
dst = args[0]
#
if subfolder:
dst = os.path.join(dst, r[0], r[1])
saveimages(imglist, dst, overwrite)
except Exception as e:
print("Error:", sys.exc_info()[1])
else:
print("Error: url invalida")
El tercer hilo de mlp sucede el 14 de febrero es casi una coincidencia pero no sabr铆a decir si es buena o mala.
https://www.youtube.com/watch?v=bhPkYKpaz0k
>>65374
Lo se anon, a煤n as铆 feliz d铆a.
>>38666
Ya te aprob茅 el PR negrito, gracias por aportar, en unos d铆as ver茅 si le hago mantenimiento al scraper en JS