• Publicidad

Dudas con HTML::Parser

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

Re: Dudas con HTML::Parser

Notapor Leo_Gutierrez » 2010-04-05 18:46 @823

Gracias, panterozo.

Ya he resuelto todos los problemas, así queda finalmente:

Sintáxis: [ Descargar ] [ Ocultar ]
Using perl Syntax Highlighting
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. use LWP::Simple;
  5. use Gtk2 '-init';
  6. use constant TRUE => 1;
  7. use constant FALSE => 0;
  8.  
  9. binmode STDOUT, ":encoding(UTF-8)";
  10.  
  11. sub raeSearch()
  12. {
  13.         my $rae = get("http://buscon.rae.es/draeI/SrvltGUIBusUsual?LEMA=$_[0]");
  14.         my $resultado;
  15.         while ($rae =~ m/name="[\d_]+"> (.*?) <\/p/smgix)
  16.         {
  17.                 my $desc = $1;
  18.                 # Quitar las marcas HTML
  19.                 $desc =~ s/<.*?>//gsm;
  20.                 # Quitar los espacios a los lados
  21.                 $desc =~ s/^\s+//sm;
  22.                 $desc =~ s/\s+$//sm;
  23.                 # Quitar espacios excesivos
  24.                 $desc =~ s/\s+/ /gsm;
  25.                 $resultado .= "$desc\n";
  26.         }
  27.                 return $resultado;
  28. }
  29.  
  30. # Propiedades de ventana:
  31. my $window = Gtk2::Window->new();
  32. $window->set_title("Rae Search");
  33. $window->set_border_width(3);
  34. $window->signal_connect(destroy => sub{Gtk2->main_quit});
  35. $window->set_auto_startup_notification(TRUE);
  36. $window->set_decorated(TRUE);
  37. $window->set_default_icon_from_file("camel.ico");
  38. $window->move(0, 0);
  39. $window->resize(700, 100);
  40. $window->set_resizable(TRUE);
  41.  
  42. # Frame:
  43. my $frame = Gtk2::Frame->new("Entrada");
  44.  
  45. # VBox:
  46. my $vbox = Gtk2::VBox->new(FALSE, 10);
  47. $vbox->pack_start($frame, TRUE, TRUE, 0);
  48.  
  49. # HBox:
  50. my $hbox = Gtk2::HBox->new(FALSE, 6);
  51.  
  52. # Entry:
  53. my $dir_entry = Gtk2::Entry->new_with_max_length(30);
  54. $dir_entry->set_text("encono");
  55. $dir_entry->set_activates_default(FALSE);
  56. $dir_entry->set_position(100);
  57.  
  58. # Button:
  59. my $button = Gtk2::Button->new("_Buscar");
  60. $button->set_focus_on_click(TRUE);
  61. my $rae;
  62.  
  63. # TextView  :
  64. my $textview = Gtk2::TextView->new();
  65. $textview->set_border_window_size('top', 1);
  66. my $buffer = $textview->get_buffer;
  67.  
  68. $button->signal_connect(clicked => sub
  69.         {
  70.                 $buffer->set_text(&raeSearch($dir_entry->get_text));
  71.         }
  72. );
  73.  
  74. # Scroll Window :
  75.  
  76. my $scroll = Gtk2::ScrolledWindow->new();
  77. $scroll->set_policy('automatic', 'automatic');
  78. $scroll->set_shadow_type('out');
  79.  
  80. $scroll->add($textview);
  81.  
  82. $vbox->pack_end($scroll, TRUE, TRUE, 0);
  83.  
  84. $frame->add($hbox);
  85.  
  86. $hbox->pack_start($dir_entry, FALSE, FALSE, 0);
  87. $hbox->pack_start($button, FALSE, FALSE, 0);
  88.  
  89. $window->add($vbox);
  90. $window->show_all;
  91. Gtk2->main;
Coloreado en 0.004 segundos, usando GeSHi 1.0.8.4
Leo_Gutierrez
Perlero nuevo
Perlero nuevo
 
Mensajes: 91
Registrado: 2008-08-20 23:38 @026

Publicidad

Anterior

Volver a Básico

¿Quién está conectado?

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