Test Foro de elhacker.net SMF 2.1

Programación => Scripting => Mensaje iniciado por: ¨°o.O (ßa¢Kg|å§§) O.o° en 28 Marzo 2010, 15:58 PM

Título: Expresiones regulares --->(Python)[Resuelto]
Publicado por: ¨°o.O (ßa¢Kg|å§§) O.o° en 28 Marzo 2010, 15:58 PM
Hola a todos, ::)

Estoy liado haciendo un script en python y tengo que quitar cosas de los links que recorro por el for de una página web.

El bucle lo paso asi:
Código (python) [Seleccionar]

for link in br.links(url_regex=re.compile('.*')):
   print link


Una vez que lo paso me muestra todas esto y otros links que no necesito parsear de:
Link(base_url='file:/home/alejandro/Escritorio/1biinox.php.html', url='http://vale.com/scripts/runner.php?IM=45b2a2ec96953.', text='* Ejemplo* aquamails', tag='a', attrs=[('href', 'http://vale.com/scripts/runner.php?IM=45b2a2ec96953.'), ('target', '_inbox')])

En el link de arriba quiero cojer todo lo que esta en url osea todo el link:
http://vale.com/scripts/runner.php?IM=45b2a2ec96953.

Y lo demás descartarlo.
¿Como lo podria hacer?

Saludos
Backglass





Título: Re: Expresiones regulares --->(Python)
Publicado por: leogtz en 28 Marzo 2010, 19:23 PM
Aunque no poner todo el trozo de código.

Esto lo encontré en una web, solo lo modifiqué un poco:

Código (python) [Seleccionar]
#!/usr/bin/python
import re
cadena = "Link(base_url='file:/home/alejandro/Escritorio/1biinox.php.html', url='http://vale.com/scripts/runner.php?IM=45b2a2ec96953.', text='* Ejemplo* aquamails', tag='a', attrs=[('href', 'http://vale.com/scripts/runner.php?IM=45b2a2ec96953.'), ('target', '_inbox')])";
print cadena, "\n\n";
t = cadena[cadena.find("http://"):]
print t,"\n";
t = t[:t.find(" ")]
print t


http://www.amk.ca/python/howto/regex/
http://docs.python.org/library/re.html#re-syntax
http://stackoverflow.com/questions/520031/whats-the-cleanest-way-to-extract-urls-from-a-string-using-python
Título: Re: Expresiones regulares --->(Python)
Publicado por: Novlucker en 29 Marzo 2010, 02:21 AM
Pista :P

Código (python) [Seleccionar]
import html.parser

Saludos