Re: recuperar contenido html

Chema Cortes <[email protected]>
Newsgroups gmane.comp.python.general.castellano
Organization ch3m4.org
Message-ID <[email protected]>
El Martes, 20 de Octubre de 2009 22:43:58 Luis Miguel Morillas escribió:


> La solución más rápida es la siguiente. Usa amara2 (easy_install amara)
> 
> from amara.bindery import html
> 
> doc =
>  html.parse(r'http://nlel.areyesp77.operaunite.com/file_sharing/content/art
> icle_1.html') comentarios = doc.xml_select(u"//span[@class='score']")
> for c in comentarios:
>     texto_comentario = unicode(c)
>     if 'Funny' in texto_comentario or 'Insightful' in texto_comentario:
>         print texto_comentario  # haz aquí lo que consideres con el
>  comentario.
> 
> Es esto lo que necesitas?

Por lo que se ve, hay que relacionar la puntuación con los comentarios. He 
probado un poco y lo he conseguido con el '..' de XPath para subir un nivel:


from amara.bindery import html

doc=html.parse(r'http://nlel.areyesp77.operaunite.com/file_sharing/content/article_1.html')
comentarios=doc.xml_select(u"//div[@class='commentBody']/..")
for c in comentarios:
    score=unicode(c.xml_select(u"//span[@class='score']")[0]))
    if u'Funny' in score or u'Insightful' in score:
        comment=unicode(c.div[1])
        print score, comment



Por cierto, Luis Miguel, el ftp de Uche no estaba operativo. Me he tenido que 
instalar Amara a través del repositorio mercurial.

_______________________________________________
Lista de correo Python-es 
http://listas.aditel.org/listinfo/python-es
FAQ: http://listas.aditel.org/faqpyes
signature.asc (application/pgp-signature, 190 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.11 (GNU/Linux)

iD8DBQBK3nCRa1V4BoHtm6IRAhCKAKCFqrBnbfrFY1iJ/TIU8psT6ENtuQCeNlPQ
6LK41yTJ5sf1wiAH74HYVwo=
=LGJ0
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.