Con lxml es muchisimo mas simple que con BeautifulSoup, sobretodo si sabes css.

Un saludo.
Andrei.

El día 5 de marzo de 2011 18:51, Francisco Rivas
<franciscojriv...@gmail.com> escribió:
> Hola *,
> yo tomaria la sugerencia de usar BeautifulSoup es bastante simple :
> Estoy paritieno del hecho de que ese codigo html es igual en todos los tr es
> decir se mentienen los 3 td.
> Seria algo como :
> from BeautifulSoup import BeautifulSoup
> page = """<tr align="RIGHT" bgcolor="#ffffff">
> <td nowrap="nowrap" align="center">Cuentos Infantiles</td>
> <td><font color="#008000">Cenicienta</font></td>
> <td><font color="#008000">25.00</font></td>
> </tr>"""
> soup = BeautifulSoup(page)
> precio = str(soup.findAll("td")[2].text) # debido a que te interesa el
> 25.00
> Quiza eso te sirva :D
>
> On Wed, Mar 2, 2011 at 18:23, lopz <lowlife...@gmail.com> wrote:
>>
>> Yo si es que solo necesitas eso usaría expresiones regulares, van y
>> bien y no dependes de módulos externos
>> ahora si se trata de usar un módulo tiraría de [1] y también he leído
>> muy bien de lxml
>>
>> [1]  http://www.crummy.com/software/BeautifulSoup/
>>
>> 2011/3/2 Nekmo <conta...@nekmo.com>:
>> > Yo con lxml suelo usar una funcionalidad que me permite filtrar usando
>> > CSS, lo cual me es una pasada :D Además tienes lxml tanto en Python3
>> > como en 2.x
>> >
>> > Un cordial saludo:
>> > -- Nekmo.
>> >
>> > Sitio web: http://nekmo.com
>> > Dirección de contacto: conta...@nekmo.com
>> > XMPP/Jabber: conta...@nekmo.com
>> > Identi.ca: http://identi.ca/nekmo
>> > Diaspora: Nekmo
>> >
>> >
>> >
>> > 2011/3/2 Luis Miguel Morillas <moril...@gmail.com>:
>> >> El día 2 de marzo de 2011 15:23, (P@vel) <pdlo...@uci.cu> escribió:
>> >>> Como puedo de un archivo html cojer todas las etiquetas <tr></tr> que
>> >>> tengan
>> >>> un <td></td> que se llame cuentos infantiles por ejemplo, y guardar el
>> >>> valor
>> >>> que tenga los demas <td> de ese <tr>, es decir cojer los valores de
>> >>> todas
>> >>> las columnas de esa fila, por ejemplo: cenicienta, 25.00
>> >>>
>> >>> <tr align="RIGHT" bgcolor="#ffffff">
>> >>> <td nowrap="nowrap" align="center">Cuentos Infantiles</td>
>> >>> <td><font color="#008000">Cenicienta</font></td>
>> >>> <td><font color="#008000">25.00</font></td>
>> >>> </tr>
>> >>>
>> >>
>> >> Yo lo hago así usando una expresión xpath con amara:
>> >>
>> >> from amara.bindery import html
>> >>
>> >> doc = html.parse(url_de_la_web)
>> >> cuentos = doc.xml_select(u'//tr[td="Cuentos Infantiles"]')
>> >>
>> >> # nodos html
>> >> for cuento in cuentos:
>> >>    cuento.xml_encode()
>> >>
>> >> # sólo contenido
>> >> for cuento in cuentos:
>> >>    for datos in cuento.xml_children:
>> >>        print datos,
>> >>
>> >>
>> >> Si quieres probar amara sin instalar, he creado un amaraPortable para
>> >> windows:
>> >> https://bitbucket.org/lmorillas/amaraportable/downloads/AmaraPortable.exe
>> >>
>> >>
>> >> Saludos,
>> >>
>> >> -- luismiguel
>> >>
>> >>> _______________________________________________
>> >>> Python-es mailing list
>> >>> Python-es@python.org
>> >>> http://mail.python.org/mailman/listinfo/python-es
>> >>> FAQ: http://python-es-faq.wikidot.com/
>> >>>
>> >>>
>> >> _______________________________________________
>> >> Python-es mailing list
>> >> Python-es@python.org
>> >> http://mail.python.org/mailman/listinfo/python-es
>> >> FAQ: http://python-es-faq.wikidot.com/
>> >>
>> > _______________________________________________
>> > Python-es mailing list
>> > Python-es@python.org
>> > http://mail.python.org/mailman/listinfo/python-es
>> > FAQ: http://python-es-faq.wikidot.com/
>> >
>>
>>
>>
>> --
>> lopz es libre, usa --> GNU/linux gentoo
>>
>> +--[RSA 2048]--+
>> |  ..o.o=+       |
>> |   o =o*.+      |
>> |  . . *oO .      |
>> |     .EBoo      |
>> |      o.S         |
>> +--[lopz.org]--+
>> _______________________________________________
>> Python-es mailing list
>> Python-es@python.org
>> http://mail.python.org/mailman/listinfo/python-es
>> FAQ: http://python-es-faq.wikidot.com/
>
>
> _______________________________________________
> Python-es mailing list
> Python-es@python.org
> http://mail.python.org/mailman/listinfo/python-es
> FAQ: http://python-es-faq.wikidot.com/
>
>



-- 
http://twitter.com/andsux
http://www.niwi.be
****
http://www.freebsd.org/
http://www.postgresql.org/
http://www.python.org/
http://www.djangoproject.com/

"Linux is for people who hate Windows, BSD is for people who love UNIX"
"Social Engineer -> Because there is no patch for human stupidity"
_______________________________________________
Python-es mailing list
Python-es@python.org
http://mail.python.org/mailman/listinfo/python-es
FAQ: http://python-es-faq.wikidot.com/

Reply via email to