• Publicidad

Obtener datos tabla HTML

¿Apenas comienzas con Perl? En este foro podrás encontrar y hacer preguntas básicas de Perl con respuestas aptas a tu nivel.

Obtener datos tabla HTML

Notapor magiza83 » 2012-03-28 06:07 @296

Hola,
Estoy intentando parsear un html para obtener los datos de las tablas html.

El código html es:
Sintáxis: [ Descargar ] [ Ocultar ]
Using html4strict Syntax Highlighting
  1. Content-type: text/html
  2.  
  3. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"><html>
  4. <head><title>Replication Status</title>
  5. <style text/css>
  6. Body, p, table, td, ul, li {color: #000000; font-family: Arial, Helvetica, sans-serif; font-size: 12px;}
  7. A {color:blue; text-decoration: none;}
  8. BODY {font-family: arial, helvetica, sans-serif}
  9. P {font-family: arial, helvetica, sans-serif}
  10. TH {font-weight: bold; font-family: arial, helvetica, sans-serif}
  11. TD {font-family: arial, helvetica, sans-serif}
  12. .bgColor1  {background-color: #003366;}
  13. .bgColor4  {background-color: #cccccc;}
  14. .bgColor5  {background-color: #999999;}
  15. .bgColor9  {background-color: #336699;}
  16. .bgColor13 {background-color: #ffffff;}
  17. .bgColor16 {background-color: #6699cc;}
  18. .text8  {color: #0099cc; font-size: 11px; font-weight: bold;}
  19. .text28 {color: #ffcc33; font-size: 12px; font-weight: bold;}
  20. .areatitle {font-weight: bold; color: #ffffff; font-family: arial, helvetica, sans-serif}
  21. .page-title {font-weight: bold; font-size: larger; font-family: arial, helvetica, sans-serif}
  22. .page-subtitle {font-weight: bold; font-family: arial, helvetica, sans-serif}
  23. </style></head>
  24. <body class=bgColor4>
  25. <table border=0 cellspacing=0 cellpadding=10 width=100% class=bgColor1>
  26. <tr><td><font class=text8>Wed Mar 28 2012 12:55:26</font></td>
  27. <td align=center class=page-title><font color=#0099CC>Directory Server Replication Status</font>
  28. </td><td align=right valign=center width=25%><font class=text8>Version 1.0</font></td></table>
  29.  
  30. <center><p><font class=page-subtitle color=#0099cc>Time Lag Legend:</font><p>
  31. <table cellpadding=6 cols=3 width=40%>
  32. <tr>
  33.  
  34. <td bgcolor=#ccffcc><center>within 5 min</center></td>
  35.  
  36. <td bgcolor=#ffffcc><center>within 60 min</center></td>
  37.  
  38. <td bgcolor=#ffcccc><center>over 60 min</center></td>
  39.  
  40. <td bgcolor=red><center>server n/a</center></td>
  41. </table></center>
  42. <p><p><hr><p>
  43.  
  44. <p><center class=page-subtitle><font color=#0099cc>
  45. Master:&nbsp <a href="ldap://ldap2.test.com:1389/">ldap2.test.com:1389</a></center>
  46.  
  47. <p><table border=0 cellspacing=1 cellpadding=6 cols=10 width=100% class=bgColor9>
  48.  
  49. <tr><td colspan=10><center>
  50. <font class=areatitle>Replica ID:&nbsp;</font><font class=text28>1</font>
  51. <font class=areatitle>Replica Root:&nbsp;</font><font class=text28>dc=org</font>
  52. <font class=areatitle>Max CSN:&nbsp;</font><font class=text28>4f71ce1e000500010000 (03/27/2012 16:26:38 5 0)</font>
  53.  
  54. <tr class=bgColor16>
  55. <th nowrap>Receiver</th>
  56. <th nowrap>Time Lag</th>
  57. <th nowrap>Max CSN</th>
  58. <th nowrap>Last Modify Time</th>
  59. <th nowrap>Supplier</th>
  60. <th nowrap>Sent/Skipped</th>
  61. <th nowrap>Update Status</th>
  62. <th nowrap>Update Started</th>
  63. <th nowrap>Update Ended</th>
  64. <th nowrap colspan=2>Schedule</th>
  65. <th nowrap>SSL?</th>
  66. </tr>
  67.  
  68. <tr class=bgColor13>
  69. <td rowspan=1 width=5% class=bgColor5><a href="ldap://ldap2-2.test.com:1389/">ldap2-2.test.com:1389</a><BR>Type: master</td>
  70. <td rowspan=1 width=5% nowrap bgcolor=#ccffcc><center>0:00:00</center></td>
  71. <td rowspan=1 width=15% nowrap>4f71ce1e000500010000<br>(03/27/2012 16:26:38 5 0)</td>
  72. <td rowspan=1 width=15% nowrap>3/27/2012 16:26:38</td>
  73. <td width=5% nowrap><center>ldap2.test.com:1389</center></td>
  74. <td width=3% nowrap>12 / 0</td>
  75. <td width=20% nowrap>0 Replica acquired successfully: Incremental update succeeded</td>
  76. <td nowrap>03/27/2012 17:21:21</td>
  77. <td nowrap>03/27/2012 17:21:21</td>
  78. <td colspan=2 width=10% nowrap>always in sync</td>
  79. <td width=3% nowrap class=bgColor5>n</td>
  80. </table>
  81. <p><p><hr><p>
  82.  
  83. <p><center class=page-subtitle><font color=#0099cc>
  84. Master:&nbsp <a href="ldap://ldap2-2.test.com:1389/">ldap2-2.test.com:1389</a></center>
  85.  
  86. <p><table border=0 cellspacing=1 cellpadding=6 cols=10 width=100% class=bgColor9>
  87.  
  88. <tr><td colspan=10><center>
  89. <font class=areatitle>Replica ID:&nbsp;</font><font class=text28>2</font>
  90. <font class=areatitle>Replica Root:&nbsp;</font><font class=text28>dc=org</font>
  91. <font class=areatitle>Max CSN:&nbsp;</font><font class=text28>4f71daf3000000020000 (03/27/2012 17:21:23)</font>
  92.  
  93. <tr class=bgColor16>
  94. <th nowrap>Receiver</th>
  95. <th nowrap>Time Lag</th>
  96. <th nowrap>Max CSN</th>
  97. <th nowrap>Last Modify Time</th>
  98. <th nowrap>Supplier</th>
  99. <th nowrap>Sent/Skipped</th>
  100. <th nowrap>Update Status</th>
  101. <th nowrap>Update Started</th>
  102. <th nowrap>Update Ended</th>
  103. <th nowrap colspan=2>Schedule</th>
  104. <th nowrap>SSL?</th>
  105. </tr>
  106.  
  107. <tr class=bgColor13>
  108. <td rowspan=1 width=5% class=bgColor5><a href="ldap://ldap2.test.com:1389/">ldap2.test.com:1389</a><BR>Type: master</td>
  109. <td rowspan=1 width=5% nowrap bgcolor=#ccffcc><center>0:00:00</center></td>
  110. <td rowspan=1 width=15% nowrap>4f71daf3000000020000<br>(03/27/2012 17:21:23)</td>
  111. <td rowspan=1 width=15% nowrap>3/27/2012 17:21:21</td>
  112. <td width=5% nowrap><center>ldap2-2.test.com:1389</center></td>
  113. <td width=3% nowrap>0 / 0</td>
  114. <td width=20% nowrap>0 No replication sessions started since server startup</td>
  115. <td nowrap>n/a</td>
  116. <td nowrap>n/a</td>
  117. <td colspan=2 width=10% nowrap>always in sync</td>
  118. <td width=3% nowrap class=bgColor5>n</td>
  119. </table>
  120.  
Coloreado en 0.005 segundos, usando GeSHi 1.0.8.4


Lo que me gustaria obtener son los datos de las etiquetas <th> y sus valores en <td>. He intentado seguir algún manual sobre parseo de HTML, pero no lo tengo claro y no consigo sacar ningún valor.

¿Podéis guiarme sobre cómo hacerlo?

Este HTML es generado por un script, que crea las dos tablas (1 por cada host), la idea es que este HTML vaya creciendo y generando un acumulado. Lo que me gustaría es solo leer las dos últimas tablas generadas (es decir, las dos últimas tablas que aparecen en el fichero), ya que son las referentes a la última ejecución del script.

Saludos y muchas gracias.
magiza83
Perlero nuevo
Perlero nuevo
 
Mensajes: 14
Registrado: 2012-02-22 05:29 @270

Publicidad

Re: Obtener datos tabla HTML

Notapor explorer » 2012-03-28 12:02 @543

Buenas...

Esta es una posible solución:
Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. #!/usr/bin/perl
  2. use Modern::Perl '2012';
  3. use Mojo::Asset::File;
  4. use Mojo::DOM;
  5. use List::MoreUtils 'zip';
  6.  
  7. my $archivo = "code_30276.html";                            # Leemos el archivo
  8.  
  9. my $file_asset = Mojo::Asset::File->new(path => $archivo);  # Crea un contenedor en un archivo
  10.  
  11. my $mojo = Mojo::DOM->new($file_asset->slurp);              # Y lo leemos e interpretamos sintácticamente
  12.  
  13. my $tabla = $mojo->find("table")->[-1];                     # Buscamos la última tabla
  14.  
  15. sub texto {
  16.         $_[0]->text;                                        # Lo que queremos hacer con cada elemento: su texto
  17. }
  18.  
  19.                                                             # La magia: buscar, extraer, transformar y barajar
  20. my %datos = zip @{ $tabla->find("tr[class=bgColor16] th")->map(\&texto) },
  21.                 @{ $tabla->find("tr[class=bgColor13] td")->map(\&texto) };
  22.  
  23. use Data::Dumper::Simple;
  24. say Dumper %datos;                                          # Resultado
  25.  
  26. __END__
Coloreado en 0.002 segundos, usando GeSHi 1.0.8.4

La salida es:
Sintáxis: [ Descargar ] [ Ocultar ]
Using text Syntax Highlighting
%datos = (
           'Update Started' => 'n/a',
           'Update Status' => '0 No replication sessions started since server startup',
           'Update Ended' => 'n/a',
           'Time Lag' => '',
           'Last Modify Time' => '3/27/2012 17:21:21',
           'Sent/Skipped' => '0 / 0',
           'SSL?' => 'n',
           'Receiver' => 'Type: master',
           'Supplier' => '',
           'Schedule' => 'always in sync',
           'Max CSN' => '4f71daf3000000020000 (03/27/2012 17:21:23)'
         );
Coloreado en 0.000 segundos, usando GeSHi 1.0.8.4
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14480
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España

Re: Obtener datos tabla HTML

Notapor magiza83 » 2012-04-02 01:14 @093

¡Muchas gracias, explorer!

Tendré que revisar bien qué hace este módulo para entender bien el script, ¡pero era justo lo que estaba buscando!

¡Saludos!
magiza83
Perlero nuevo
Perlero nuevo
 
Mensajes: 14
Registrado: 2012-02-22 05:29 @270

Re: Obtener datos tabla HTML

Notapor magiza83 » 2012-04-02 03:57 @206

Hola,

al intentar ejecutar el script en mi máquina no funcionaba por no tener los módulos, pero al intentar instalarlos obtengo los siguientes errores:

cpan -i Mojo::Asset::File
Sintáxis: [ Descargar ] [ Ocultar ]
Using text Syntax Highlighting
...
...
...
Manifying blib/man3/Mojolicious::Command::daemon.3pm
Manifying blib/man3/Mojo::Parameters.3pm
  SRI/Mojolicious-2.70.tar.gz
  /usr/bin/make -- OK
Running make test
PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t t/*/*.t
t/mojo/app.t ............................... Can't locate Time/HiRes.pm in @INC (@INC contains: /root/.cpan/build/Mojolicious-2.70-mJrmeB/blib/lib /root/.cpan/build/Mojolicious-2.70-mJrmeB/blib/arch /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at /root/.cpan/build/Mojolicious-2.70-mJrmeB/blib/lib/Mojo/IOLoop/Stream.pm line 6.
BEGIN failed--compilation aborted at /root/.cpan/build/Mojolicious-2.70-mJrmeB/blib/lib/Mojo/IOLoop/Stream.pm line 6.
Compilation failed in require at /root/.cpan/build/Mojolicious-2.70-mJrmeB/blib/lib/Mojo/IOLoop.pm line 8.
BEGIN failed--compilation aborted at /root/.cpan/build/Mojolicious-2.70-mJrmeB/blib/lib/Mojo/IOLoop.pm line 8.
Compilation failed in require at /root/.cpan/build/Mojolicious-2.70-mJrmeB/blib/lib/Mojo/UserAgent.pm line 6.
BEGIN failed--compilation aborted at /root/.cpan/build/Mojolicious-2.70-mJrmeB/blib/lib/Mojo/UserAgent.pm line 6.
Compilation failed in require at /root/.cpan/build/Mojolicious-2.70-mJrmeB/blib/lib/Mojo.pm line 8.
BEGIN failed--compilation aborted at /root/.cpan/build/Mojolicious-2.70-mJrmeB/blib/lib/Mojo.pm line 8.
Compilation failed in require at t/mojo/app.t line 16.
BEGIN failed--compilation aborted at t/mojo/app.t line 16.
# Looks like your test exited with 2 before it could output anything.
t/mojo/app.t ............................... Dubious, test returned 2 (wstat 512, 0x200)
Failed 54/54 subtests
t/mojo/asset.t ............................. ok
...
...
...
Coloreado en 0.000 segundos, usando GeSHi 1.0.8.4


¿Alguna idea de por qué falla? Sigo googleando a ver por qué falla.

La versión de Perl es:
Sintáxis: [ Descargar ] [ Ocultar ]
Using text Syntax Highlighting
perl -v

This is perl, v5.10.1 (*) built for x86_64-linux-thread-multi

Copyright 1987-2009, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
Coloreado en 0.000 segundos, usando GeSHi 1.0.8.4



Saludos y muchas gracias.
magiza83
Perlero nuevo
Perlero nuevo
 
Mensajes: 14
Registrado: 2012-02-22 05:29 @270

Re: Obtener datos tabla HTML

Notapor explorer » 2012-04-02 05:46 @282

El error dice Can't locate Time/HiRes.pm, que quiere decir que no localiza el módulo Time::HiRes.

Es extraño que el comando cpan no te haya preguntado si quieres instalar los módulos de los que depende Mojo::Asset::File.

Es cuestión de la configuración del comando cpan el que te lo pregunte, o no. Puedes cambiarlo, o seguir instalando los módulos que te faltan, uno a uno.

Para cambiar la configuración de cpan, ejecútalo sin ningún argumento, para entrar en su shell. Luego, allí, escribes los comandos:

o conf prerequisites_policy follow
o conf commit


Y ya está. Con eso, instalará los módulos dependientes, sin preguntar. Si quieres que sí te pregunte antes de instalarlos, cambia 'follow' por 'ask'.
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14480
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España

Re: Obtener datos tabla HTML

Notapor magiza83 » 2012-04-02 08:36 @400

Hola,

¡Gracias! Ahora ya puedo ejecutar el script.

Aunque encuentro varios problemas en la salida del script y como además no acabo de entender bien cómo busca la información no soy capaz de modificarlo. Además ahora el html se ha complicado un poco más debido a cambios realizados en el entorno y no soy capaz de utilizar el código de Perl para adaptarlo al nuevo HTML.

Ahora el html es el siguiente, la estructura más o menos es igual solo que se han añadido nuevos:
Sintáxis: [ Descargar ] [ Ocultar ]
Using html4strict Syntax Highlighting
  1. Content-type: text/html
  2.  
  3. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"><html>
  4. <head><title>Replication Status</title>
  5. <style text/css>
  6. Body, p, table, td, ul, li {color: #000000; font-family: Arial, Helvetica, sans-serif; font-size: 12px;}
  7. A {color:blue; text-decoration: none;}
  8. BODY {font-family: arial, helvetica, sans-serif}
  9. P {font-family: arial, helvetica, sans-serif}
  10. TH {font-weight: bold; font-family: arial, helvetica, sans-serif}
  11. TD {font-family: arial, helvetica, sans-serif}
  12. .bgColor1  {background-color: #003366;}
  13. .bgColor4  {background-color: #cccccc;}
  14. .bgColor5  {background-color: #999999;}
  15. .bgColor9  {background-color: #336699;}
  16. .bgColor13 {background-color: #ffffff;}
  17. .bgColor16 {background-color: #6699cc;}
  18. .text8  {color: #0099cc; font-size: 11px; font-weight: bold;}
  19. .text28 {color: #ffcc33; font-size: 12px; font-weight: bold;}
  20. .areatitle {font-weight: bold; color: #ffffff; font-family: arial, helvetica, sans-serif}
  21. .page-title {font-weight: bold; font-size: larger; font-family: arial, helvetica, sans-serif}
  22. .page-subtitle {font-weight: bold; font-family: arial, helvetica, sans-serif}
  23. </style></head>
  24. <body class=bgColor4>
  25. <table border=0 cellspacing=0 cellpadding=10 width=100% class=bgColor1>
  26. <tr><td><font class=text8>Mon Apr  12:38:01 2</font></td>
  27. <td align=center class=page-title><font color=#0099CC>Directory Server Replication Status</font>
  28. </td><td align=right valign=center width=25%><font class=text8>Version 1.0</font></td></table>
  29.  
  30. <center><p><font class=page-subtitle color=#0099cc>Time Lag Legend:</font><p>
  31. <table cellpadding=6 cols=3 width=40%>
  32. <tr>
  33.  
  34. <td bgcolor=#ccffcc><center>within 5 min</center></td>
  35.  
  36. <td bgcolor=#ffffcc><center>within 60 min</center></td>
  37.  
  38. <td bgcolor=#ffcccc><center>over 60 min</center></td>
  39.  
  40. <td bgcolor=red><center>server n/a</center></td>
  41. </table></center>
  42. <p><p><hr><p>
  43.  
  44. <p><center class=page-subtitle><font color=#0099cc>
  45. Master:&nbsp <a href="ldap://ldap1-1.ddol-test.com:1389/">ldap1-1.ddol-test.com:1389</a></center>
  46.  
  47. <p><table border=0 cellspacing=1 cellpadding=6 cols=10 width=100% class=bgColor9>
  48.  
  49. <tr><td colspan=10><center>
  50. <font class=areatitle>Replica ID:&nbsp;</font><font class=text28>1</font>
  51. <font class=areatitle>Replica Root:&nbsp;</font><font class=text28>dc=org</font>
  52. <font class=areatitle>Max CSN:&nbsp;</font><font class=text28>4f797f67000000010000 (04/02/2012 12:28:55)</font>
  53.  
  54. <tr class=bgColor16>
  55. <th nowrap>Receiver</th>
  56. <th nowrap>Time Lag</th>
  57. <th nowrap>Max CSN</th>
  58. <th nowrap>Last Modify Time</th>
  59. <th nowrap>Supplier</th>
  60. <th nowrap>Sent/Skipped</th>
  61. <th nowrap>Update Status</th>
  62. <th nowrap>Update Started</th>
  63. <th nowrap>Update Ended</th>
  64. <th nowrap colspan=2>Schedule</th>
  65. <th nowrap>SSL?</th>
  66. </tr>
  67.  
  68. <tr class=bgColor13>
  69. <td rowspan=1 width=5% class=bgColor5><a href="ldap://ldap1-2.ddol-test.com:1389/">ldap1-2.ddol-test.com:1389</a><BR>Type: master</td>
  70. <td rowspan=1 width=5% nowrap bgcolor=#ccffcc><center>0:00:00</center></td>
  71. <td rowspan=1 width=15% nowrap>4f797f67000000010000<br>(04/02/2012 12:28:55)</td>
  72. <td rowspan=1 width=15% nowrap>4/2/2012 12:28:54</td>
  73. <td width=5% nowrap><center>ldap1-1.ddol-test.com:1389</center></td>
  74. <td width=3% nowrap>1077 / 0</td>
  75. <td width=20% nowrap>0 Replica acquired successfully: Incremental update succeeded</td>
  76. <td nowrap>04/02/2012 12:33:56</td>
  77. <td nowrap>04/02/2012 12:33:56</td>
  78. <td colspan=2 width=10% nowrap>always in sync</td>
  79. <td width=3% nowrap class=bgColor5>n</td>
  80.  
  81. <tr class=bgColor13>
  82. <td rowspan=2 width=5% class=bgColor5><a href="ldap://ldap2-1.ddol-test.com:1389/">ldap2-1.ddol-test.com:1389</a><BR>Type: consumer</td>
  83. <td rowspan=2 width=5% nowrap bgcolor=#ccffcc><center>0:00:00</center></td>
  84. <td rowspan=2 width=15% nowrap>4f797f67000000010000<br>(04/02/2012 12:28:55)</td>
  85. <td rowspan=2 width=15% nowrap>4/2/2012 12:31:44</td>
  86. <td width=5% nowrap><center>ldap1-1.ddol-test.com:1389</center></td>
  87. <td width=3% nowrap>1266 / 0</td>
  88. <td width=20% nowrap>0 Replica acquired successfully: Incremental update succeeded</td>
  89. <td nowrap>04/02/2012 12:36:46</td>
  90. <td nowrap>04/02/2012 12:36:46</td>
  91. <td colspan=2 width=10% nowrap>always in sync</td>
  92. <td width=3% nowrap class=bgColor5>n</td>
  93.  
  94. <tr class=bgColor13>
  95. <td width=5% nowrap><center>ldap1-2.ddol-test.com:1389</center></td>
  96. <td width=3% nowrap>0 / 0</td>
  97. <td width=20% nowrap>0 Replica acquired successfully: Incremental update succeeded</td>
  98. <td nowrap>04/02/2012 12:34:54</td>
  99. <td nowrap>04/02/2012 12:34:54</td>
  100. <td colspan=2 width=10% nowrap>always in sync</td>
  101. <td width=3% nowrap class=bgColor5>n</td>
  102.  
  103. <tr class=bgColor13>
  104. <td rowspan=2 width=5% class=bgColor5><a href="ldap://ldap2-2.ddol-test.com:1389/">ldap2-2.ddol-test.com:1389</a><BR>Type: consumer</td>
  105. <td rowspan=2 width=5% nowrap bgcolor=#ccffcc><center>0:00:00</center></td>
  106. <td rowspan=2 width=15% nowrap>4f797f67000000010000<br>(04/02/2012 12:28:55)</td>
  107. <td rowspan=2 width=15% nowrap>4/2/2012 12:34:59</td>
  108. <td width=5% nowrap><center>ldap1-1.ddol-test.com:1389</center></td>
  109. <td width=3% nowrap>0 / 0</td>
  110. <td width=20% nowrap>0 Replica acquired successfully: Incremental update succeeded</td>
  111. <td nowrap>04/02/2012 12:36:39</td>
  112. <td nowrap>04/02/2012 12:36:39</td>
  113. <td colspan=2 width=10% nowrap>always in sync</td>
  114. <td width=3% nowrap class=bgColor5>n</td>
  115.  
  116. <tr class=bgColor13>
  117. <td width=5% nowrap><center>ldap1-2.ddol-test.com:1389</center></td>
  118. <td width=3% nowrap>1275 / 0</td>
  119. <td width=20% nowrap>0 Replica acquired successfully: Incremental update succeeded</td>
  120. <td nowrap>04/02/2012 12:34:54</td>
  121. <td nowrap>04/02/2012 12:35:01</td>
  122. <td colspan=2 width=10% nowrap>always in sync</td>
  123. <td width=3% nowrap class=bgColor5>n</td>
  124. </table>
  125. <p><p><hr><p>
  126.  
  127. <p><center class=page-subtitle><font color=#0099cc>
  128. Master:&nbsp <a href="ldap://ldap1-2.ddol-test.com:1389/">ldap1-2.ddol-test.com:1389</a></center>
  129.  
  130. <p><table border=0 cellspacing=1 cellpadding=6 cols=10 width=100% class=bgColor9>
  131.  
  132. <tr><td colspan=10><center>
  133. <font class=areatitle>Replica ID:&nbsp;</font><font class=text28>2</font>
  134. <font class=areatitle>Replica Root:&nbsp;</font><font class=text28>dc=org</font>
  135. <font class=areatitle>Max CSN:&nbsp;</font><font class=text28>4f7959ae000000020000 (04/02/2012 09:47:58)</font>
  136.  
  137. <tr class=bgColor16>
  138. <th nowrap>Receiver</th>
  139. <th nowrap>Time Lag</th>
  140. <th nowrap>Max CSN</th>
  141. <th nowrap>Last Modify Time</th>
  142. <th nowrap>Supplier</th>
  143. <th nowrap>Sent/Skipped</th>
  144. <th nowrap>Update Status</th>
  145. <th nowrap>Update Started</th>
  146. <th nowrap>Update Ended</th>
  147. <th nowrap colspan=2>Schedule</th>
  148. <th nowrap>SSL?</th>
  149. </tr>
  150.  
  151. <tr class=bgColor13>
  152. <td rowspan=1 width=5% class=bgColor5><a href="ldap://ldap1-1.ddol-test.com:1389/">ldap1-1.ddol-test.com:1389</a><BR>Type: master</td>
  153. <td rowspan=1 width=5% nowrap bgcolor=#ccffcc><center>0:00:00</center></td>
  154. <td rowspan=1 width=15% nowrap>4f7959ae000000020000<br>(04/02/2012 09:47:58)</td>
  155. <td rowspan=1 width=15% nowrap>1/1/1970 01:00:00</td>
  156. <td width=5% nowrap><center>ldap1-2.ddol-test.com:1389</center></td>
  157. <td width=3% nowrap>0 / 0</td>
  158. <td width=20% nowrap>0 Replica acquired successfully: Incremental update succeeded</td>
  159. <td nowrap>04/02/2012 12:28:54</td>
  160. <td nowrap>04/02/2012 12:28:54</td>
  161. <td colspan=2 width=10% nowrap>always in sync</td>
  162. <td width=3% nowrap class=bgColor5>n</td>
  163.  
  164. <tr class=bgColor13>
  165. <td rowspan=2 width=5% class=bgColor5><a href="ldap://ldap2-1.ddol-test.com:1389/">ldap2-1.ddol-test.com:1389</a><BR>Type: consumer</td>
  166. <td rowspan=2 width=5% nowrap bgcolor=#ccffcc><center>0:00:00</center></td>
  167. <td rowspan=2 width=15% nowrap>4f7959ae000000020000<br>(04/02/2012 09:47:58)</td>
  168. <td rowspan=2 width=15% nowrap>1/1/1970 01:00:00</td>
  169. <td width=5% nowrap><center>ldap1-2.ddol-test.com:1389</center></td>
  170. <td width=3% nowrap>0 / 0</td>
  171. <td width=20% nowrap>0 Replica acquired successfully: Incremental update succeeded</td>
  172. <td nowrap>04/02/2012 12:34:54</td>
  173. <td nowrap>04/02/2012 12:34:54</td>
  174. <td colspan=2 width=10% nowrap>always in sync</td>
  175. <td width=3% nowrap class=bgColor5>n</td>
  176.  
  177. <tr class=bgColor13>
  178. <td width=5% nowrap><center>ldap1-1.ddol-test.com:1389</center></td>
  179. <td width=3% nowrap>0 / 0</td>
  180. <td width=20% nowrap>0 Replica acquired successfully: Incremental update succeeded</td>
  181. <td nowrap>04/02/2012 12:36:46</td>
  182. <td nowrap>04/02/2012 12:36:46</td>
  183. <td colspan=2 width=10% nowrap>always in sync</td>
  184. <td width=3% nowrap class=bgColor5>n</td>
  185.  
  186. <tr class=bgColor13>
  187. <td rowspan=2 width=5% class=bgColor5><a href="ldap://ldap2-2.ddol-test.com:1389/">ldap2-2.ddol-test.com:1389</a><BR>Type: consumer</td>
  188. <td rowspan=2 width=5% nowrap bgcolor=#ccffcc><center>0:00:00</center></td>
  189. <td rowspan=2 width=15% nowrap>4f7959ae000000020000<br>(04/02/2012 09:47:58)</td>
  190. <td rowspan=2 width=15% nowrap>1/1/1970 01:00:00</td>
  191. <td width=5% nowrap><center>ldap1-2.ddol-test.com:1389</center></td>
  192. <td width=3% nowrap>0 / 0</td>
  193. <td width=20% nowrap>0 Replica acquired successfully: Incremental update succeeded</td>
  194. <td nowrap>04/02/2012 12:34:54</td>
  195. <td nowrap>04/02/2012 12:35:01</td>
  196. <td colspan=2 width=10% nowrap>always in sync</td>
  197. <td width=3% nowrap class=bgColor5>n</td>
  198.  
  199. <tr class=bgColor13>
  200. <td width=5% nowrap><center>ldap1-1.ddol-test.com:1389</center></td>
  201. <td width=3% nowrap>0 / 0</td>
  202. <td width=20% nowrap>0 Replica acquired successfully: Incremental update succeeded</td>
  203. <td nowrap>04/02/2012 12:36:39</td>
  204. <td nowrap>04/02/2012 12:36:39</td>
  205. <td colspan=2 width=10% nowrap>always in sync</td>
  206. <td width=3% nowrap class=bgColor5>n</td>
  207. </table>
  208. </table>
  209. </table>
Coloreado en 0.008 segundos, usando GeSHi 1.0.8.4


y así es como se muestra en pantalla:
Imagen

No entiendo muy bien qué hace exactamente:
Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. my $tabla = $mojo->find("table")->[-1];
Coloreado en 0.001 segundos, usando GeSHi 1.0.8.4

ya que he intentado modificarla pero no consigo obtener los demás valores de la tabla.

¡Saludos y disculpa las molestias!
magiza83
Perlero nuevo
Perlero nuevo
 
Mensajes: 14
Registrado: 2012-02-22 05:29 @270

Re: Obtener datos tabla HTML

Notapor explorer » 2012-04-02 11:44 @530

A ver... parece que el problema ha cambiado...

Decías al principio que querías sacar los valores de <th> y sus correspondientes valores <td>, pero por lo que veo, hay más de dos filas en las tablas, hay más de dos filas de <td>.

Entonces, ¿cuál es el problema que hay que resolver? ¿Qué valores hay que sacar?
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14480
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España

Re: Obtener datos tabla HTML

Notapor magiza83 » 2012-04-03 01:52 @119

Hola,

Disculpa la confusión, yo tampoco tenía claro que el script cambiaría de esa manera. La idea sería poder obtener los valor de cada línea de la tabla, y poder elegir las tablas. No sé sí me explico, pero el fichero html tendrá esta misma estructura pero siendo un acumulado de tablas y cada ejecución crea dos tablas como las que he comentado. Entonces lo ideal sería poder sacar la siguiente información por tabla cuando el master es "Master: ldap1-1.ddol-test.com:1389" y cuando master es "Master: ldap1-2.ddol-test.com:1389" (teniendo en cuenta el título que aparece arriba de la tabla).

Sintáxis: [ Descargar ] [ Ocultar ]
Using text Syntax Highlighting
%fila1 = (
                        'Receiver' => 'ldap1-2.ddol-test.com:1389 Type: master',
                        'Time Lag' => '0:00:00',
                        'Max CSN' => '4f797f67000000010000 (04/02/2012 12:28:55)'
                        'Last Modify Time' => '3/27/2012 17:21:21',
                        'Supplier' => 'ldap1-1.ddol-test.com:1389',
                        'Sent/Skipped' => '1077 / 0',
                        'Update Status' => '0 No replication sessions started since server startup',
                        'Update Started' => '04/02/2012 12:33:56',
                        'Update Ended' => '04/02/2012 12:33:56',
                        'Schedule' => 'always in sync',
                        'SSL?' => 'n',
        );
               
%lfila2 = (
                        'Receiver' => 'ldap2-1.ddol-test.com:1389 Type: consumer',
                        'Time Lag' => '0:00:00',
                        'Max CSN' => '4f797f67000000010000 (04/02/2012 12:28:55)'
                        'Last Modify Time' => '4/2/2012 12:31:44',
                        'Supplier' => 'ldap1-1.ddol-test.com:1389',
                        'Sent/Skipped' => '1266 / 0',
                        'Update Status' => '0 No replication sessions started since server startup',
                        'Update Started' => '04/02/2012 12:36:46',
                        'Update Ended' => '04/02/2012 12:36:46',
                        'Schedule' => 'always in sync',
                        'SSL?' => 'n',
        );     
               
%fila3 = (
                        'Receiver' => 'ldap2-1.ddol-test.com:1389 Type: consumer',
                        'Time Lag' => '0:00:00',
                        'Max CSN' => '4f797f67000000010000 (04/02/2012 12:28:55)'
                        'Last Modify Time' => '4/2/2012 12:31:44',
                        'Supplier' => 'ldap1-2.ddol-test.com:1389',
                        'Sent/Skipped' => '0 / 0',
                        'Update Status' => '0 No replication sessions started since server startup',
                        'Update Started' => '04/02/2012 12:34:54',
                        'Update Ended' => '04/02/2012 12:34:54',
                        'Schedule' => 'always in sync',
                        'SSL?' => 'n',
        );     
               
%fila4 = (
                        'Receiver' => 'ldap2-2.ddol-test.com:1389 Type: consumer',
                        'Time Lag' => '0:00:00',
                        'Max CSN' => '4f797f67000000010000 (04/02/2012 12:28:55)'
                        'Last Modify Time' => '4/2/2012 12:34:59',
                        'Supplier' => 'ldap1-1.ddol-test.com:1389',
                        'Sent/Skipped' => '0 / 0',
                        'Update Status' => '0 No replication sessions started since server startup',
                        'Update Started' => '04/02/2012 12:36:39',
                        'Update Ended' => '04/02/2012 12:36:39',
                        'Schedule' => 'always in sync',
                        'SSL?' => 'n',
        );     
               
%fila5 = (
                        'Receiver' => 'ldap2-2.ddol-test.com:1389 Type: consumer',
                        'Time Lag' => '0:00:00',
                        'Max CSN' => '4f797f67000000010000 (04/02/2012 12:28:55)'
                        'Last Modify Time' => '4/2/2012 12:34:59',
                        'Supplier' => 'ldap1-2.ddol-test.com:1389',
                        'Sent/Skipped' => '1275 / 0',
                        'Update Status' => '0 No replication sessions started since server startup',
                        'Update Started' => '04/02/2012 12:34:54',
                        'Update Ended' => '04/02/2012 12:35:01',
                        'Schedule' => 'always in sync',
                        'SSL?' => 'n',
        );
Coloreado en 0.000 segundos, usando GeSHi 1.0.8.4


¡Muchas gracias y disculpa la confusión!

Saludos.
magiza83
Perlero nuevo
Perlero nuevo
 
Mensajes: 14
Registrado: 2012-02-22 05:29 @270

Re: Obtener datos tabla HTML

Notapor explorer » 2012-04-03 07:59 @374

Problemas...

  • El "título" de cada tabla, realmente no pertenece a la tabla. Quiero decir que es solo un párrafo que está centrado delante de la tabla, en lugar de ir en una marca <caption>. Entonces, la búsqueda de la tabla de la que quieres sacar datos, se hace un poco más complicada ya que hay que depender de la búsqueda de ese tipo de enlaces (class=page-subtitle)
  • Hay filas que contienen celdas que están compartidas en más de una fila. La extracción de la primera fila tendrá todos los campos, pero la segunda fila, no. Esto quiere decir que hay que modificar la estructura de la propia tabla, antes de sacar la información.
¿No hay otra forma de acceder a la información?
JF^D Perl programming & Raku programming. Grupo en Telegram: https://t.me/Perl_ES
Avatar de Usuario
explorer
Administrador
Administrador
 
Mensajes: 14480
Registrado: 2005-07-24 18:12 @800
Ubicación: Valladolid, España

Re: Obtener datos tabla HTML

Notapor magiza83 » 2012-04-03 08:51 @410

Hola,

Comentaba lo del título solo para tener en cuenta que ahí está la separación y que cada tabla pertenece un host, pero ese punto no es importante. Si se puede sacar la información por tablas, ya va bien.

Por otra parte no hay problema que la segunda fila no tenga los datos ya que estos se ven también en la segunda tabla. Las tablas son complementarias y por tanto lo que está en la "segunda fila de la primera tabla" también se lee en la "primera fila de la segunda tabla".

Finalmente, el script que genera este HTML está hecho en Perl, pero no tengo lo conocimientos necesarios para modificarlo, he intentado quitar los "rowspan" pero se descuadra toda la tabla.

¡Saludos y muchas gracias por tu ayuda!
magiza83
Perlero nuevo
Perlero nuevo
 
Mensajes: 14
Registrado: 2012-02-22 05:29 @270

Siguiente

Volver a Básico

¿Quién está conectado?

Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 27 invitados

cron