Foro de elhacker.net

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
  1. for link in br.links(url_regex=re.compile('.*')):
  2.    print link
  3.  

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
  1. #!/usr/bin/python
  2. import re
  3. 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')])";
  4. print cadena, "\n\n";
  5. t = cadena[cadena.find("http://"):]
  6. print t,"\n";
  7. t = t[:t.find(" ")]
  8. print t
Código:
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
  1. import html.parser

Saludos