Ver Mensaje Individual
  #3 (permalink)  
Antiguo 10/02/2014, 13:50
Avatar de razpeitia
razpeitia
Moderador
 
Fecha de Ingreso: marzo-2005
Ubicación: Monterrey, México
Mensajes: 7.321
Antigüedad: 19 años, 1 mes
Puntos: 1360
Respuesta: Problema con for y Xpath

Código Python:
Ver original
  1. #!/usr/bin/python
  2.  
  3. import re
  4.  
  5. from lxml import html
  6. from mechanize import Browser
  7. br = Browser()
  8.  
  9.  
  10. br.set_handle_robots(False)
  11. br.addheaders = [('User-agent', 'Firefox')]
  12.  
  13. site = br.open('http://www.nic.cl/registry/Ultimos.do?t=1d')
  14.  
  15. if site.code == 200:
  16.   code = html.fromstring(site.read())
  17.   doms = code.xpath('//*[@id="box-tablaresultados"]/table/tr')
  18.   for dom in doms:
  19.     dom = ''.join(dom.xpath('./td/div[1]/a/text()'))
  20.     print dom

Solo es cuestión de conocer xpath, no realmente de python.