Hola, ¡ tengan muy buen día !
Hace unos días publiqué un par de códigos para extraer imágenes y otro para extraer enlaces, todo esto vía
Consola, así que ahora me he animado a pasarlo a un entorno un poco más "Agradable", como lo es el QT4.
Un screenshot del programa:
(http://anycode.s.gp/misubidas/extractor.png)
Ahora no usé
QTextBrowser, que usa
setHtml, preferí cambiar el panorama y utilizar
QListWidgetSin más preámbulos, el código:
# -*- coding: utf-8 -*-
#Autor : 0x5d - JaAViEr
#Twitter: 0x5d
from PyQt4 import QtCore, QtGui
import sys, urllib, re
class extractor(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.resize(602, 514)
self.setWindowTitle(QtGui.QApplication.translate("self", "Extractor de imágenes :: JaAViEr (0x5d)", None, QtGui.QApplication.UnicodeUTF8))
self.label_url = QtGui.QLabel("Url", self)
self.label_url.setGeometry(10, 15, 21, 16)
self.input_url = QtGui.QLineEdit(self)
self.input_url.setGeometry(30, 13, 561, 19)
self.label_salida = QtGui.QLabel("Salida", self)
self.label_salida.setGeometry(12, 40, 57, 15)
self.boton_extraer = QtGui.QPushButton(QtGui.QApplication.translate("self", "Extraer imágenes", None, QtGui.QApplication.UnicodeUTF8), self)
self.boton_extraer.setGeometry(469, 37, 121, 20)
self.connect(self.boton_extraer, QtCore.SIGNAL("clicked()"), self.extraer_todo)
self.listWidget = QtGui.QListWidget(self)
self.listWidget.setGeometry(QtCore.QRect(5, 60, 591, 441))
def extraer_todo(self):
url_imagenes = ""
clear = ""
i = 0
self.web = str(self.input_url.text())
for imagen in re.findall("<img (.*)>",urllib.urlopen(self.web).read()):
if "src" in imagen.lower():
for imagenes in imagen.split():
if re.findall("src=(.*)",imagenes):
clear = imagenes[:-1].replace("src=\"","")
QtGui.QListWidgetItem(self.listWidget)
self.listWidget.item(i).setText("%s.- %s"%(i, clear.replace(self.web,"")))
i+=1
app = QtGui.QApplication(sys.argv)
extraer = extractor()
extraer.show()
app.exec_()
Espero que sea de su agrado !
Fuente: http://rootcodes.com/pyqt4extraer-imagenes/
Saludos.