import re
import sys
# --------------------------------------------------------------------
# EXPRESIONES REGULARES
# JHON ALEXANDER CAMACHO URDINOLA
# jhacu1@hotmail.com
# LABORATORIO DE LENGUAJES I
# PONTIFICIA UNIVERSIDAD JAVERIANA CALI
# --------------------------------------------------------------------
# --------------------------------------------------------------------
# SE ABREN LOS ARCHIVOS
# --------------------------------------------------------------------
nombreArchivo = raw_input("Digite el path y el nombre del archivo .html o .htm: ")
try:
fp = open (nombreArchivo,"r")
except IOError:
print "NO SE PUDO ABRIR EL ARCHIVO. VERIFIQUE EL PATH O SI EXISTE EL ARCHIVO"
sys.exit()
try:
reporte = open("C:\Mis documentos\Reporte.dat","w+")
except IOError:
print "NO SE PUDO CREAR EL ARCHIVO"
sys.exit()
reporte.write("REPORTE DE LOS LINKS E IMAGENES\nCREADO POR JHON ALEXANDER CAMACHO U.\n")
reporte.write("------------------------------------\n\n")
# --------------------------------------------------------------------
# EXPRESIÓN REGULAR
# --------------------------------------------------------------------
def expresion_reg_link(texto):
resultadoLink = re.compile( "(<[L l][I i][N n][K k].*?>)",re.DOTALL)
reporte.write("LOS LINKS DE LA PÁGINA SON:\n\n")
i = 0
while i < len( resultadoLink.findall( texto ) ):
reporte.write( resultadoLink.findall( texto )[i])
reporte.write( "\n" )
i = i + 1
def expresion_reg_img(texto):
resultadoImg = re.compile( "(<[I i][M m][G g].*?>)",re.DOTALL)
reporte.write("\n\nLAS IMÁGENES DE LA PÁGINA SON:\n\n")
i = 0
while i < len( resultadoImg.findall( texto ) ):
reporte.write( resultadoImg.findall( texto )[i])
reporte.write( "\n" )
i = i + 1
# --------------------------------------------------------------------
# PROGRAMA
# --------------------------------------------------------------------
texto = fp.read()
expresion_reg_link(texto)
expresion_reg_img(texto)
fp.close()
reporte.close()
Comentarios sobre la versión: Versión 1 (1)