This is a long shot, but wth: Any Perl gurus here familiar with HTML::TokeParser use?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Angry Jew Cat - Banned for Life
    (felis madjewicus)
    • Jul 2006
    • 20368

    #1

    This is a long shot, but wth: Any Perl gurus here familiar with HTML::TokeParser use?

    Already dropped my question on a few Perl forums, and I've been detached from my regular Perl master for a few days. If you know your shit and have a moment I'd like to run a question passed you.
  • fris
    Too lazy to set a custom title
    • Aug 2002
    • 55696

    #2
    post the question here
    Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.

    Comment

    • Angry Jew Cat - Banned for Life
      (felis madjewicus)
      • Jul 2006
      • 20368

      #3
      what i'm trying to achieve is that i'd like to extract all the html contained within a specified table. i have targeted the table, and i attempted to clip out the required html using "get_trimmed_text" but it parses the html as text, so all the html tags are not saved using this method. is there an equivelant to using get_trimmed_text I could use within HTML::TokeParser or should I be looking into a different module. IS there a funtion for trimming down html in WWW::Mechanize?

      Code:
      !/usr/bin/perl
      use strict;
      use warnings;
      use HTML::TokeParser;
      use LWP::Simple;
      
      # extract.pl
      
        print "Enter the page URL: ";
            chomp( my $domain = <STDIN> );
      
        print "Enter the output HTML filename: ";
            chomp( my $html_output = <STDIN> );
      
        my $content = get($domain) or die $!;
      
        my $stream = HTML::TokeParser->new( \$content ) or die $!;
      
        while ( my $tag = $stream->get_tag( "table" ) ) {
      
            if ( $tag->[1]{cellpadding} and  $tag->[1]{cellpadding} eq '8' ) {
      
            # what do i do here?
      
            }
      
        }

      Comment

      • Angry Jew Cat - Banned for Life
        (felis madjewicus)
        • Jul 2006
        • 20368

        #4
        Shit I just found out there is an HTML::TableExtract module :D, gonna go Google now, peace...

        Comment

        • HorseShit
          Too lazy to set a custom title
          • Dec 2004
          • 17513

          #5
          peace fucker

          Comment

          • Angry Jew Cat - Banned for Life
            (felis madjewicus)
            • Jul 2006
            • 20368

            #6
            hrmmm, if i could trim all points before and after a set point in a text file somehow i could make this work. any ideas?

            Comment

            • Tempest
              Too lazy to set a custom title
              • May 2004
              • 10217

              #7
              Don't know why you're using Tokeparser for this...
              Code:
              $lchtml = lc($html);
              $start = index($lchtml, '<table');
              $end = index($lchtml, '</table>') + 8;
              $table = substr($html, $start, $end - $start);

              Comment

              • fris
                Too lazy to set a custom title
                • Aug 2002
                • 55696

                #8
                why not use php. its prob about 3 lines one to grab the content and a regex
                Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.

                Comment

                • Alky
                  Confirmed User
                  • Apr 2002
                  • 5651

                  #9
                  Originally posted by fris
                  why not use php. its prob about 3 lines one to grab the content and a regex
                  perl can use regex....

                  Comment

                  • Tempest
                    Too lazy to set a custom title
                    • May 2004
                    • 10217

                    #10
                    Originally posted by Alky
                    perl can use regex....
                    Code:
                    $html =~ /(<table.+?<\/table>)/si;
                    $table = $1;

                    Comment

                    • Angry Jew Cat - Banned for Life
                      (felis madjewicus)
                      • Jul 2006
                      • 20368

                      #11
                      Originally posted by Tempest
                      Don't know why you're using Tokeparser for this...
                      Code:
                      $lchtml = lc($html);
                      $start = index($lchtml, '<table');
                      $end = index($lchtml, '</table>') + 8;
                      $table = substr($html, $start, $end - $start);
                      I don't know why I'm using TokeParser for this either. I've just been on a google mission all day slowly stepping closer to getting my goal achieved. I'm pretty new to Perl, and real coding in general. I had a good Perl mentor for a while, but he up and disappeared for the last few days so I've been busting ass on google trying to accomplish my aims here. Never tried to manipulate a page before.

                      I got some help and have achieved my goal using HTML::TreeBuilder though. Everything has been running just skippy. I'm gonna look mor einto what you've given me though, looks as though it'd shave a few lines off my code...

                      Comment

                      • Angry Jew Cat - Banned for Life
                        (felis madjewicus)
                        • Jul 2006
                        • 20368

                        #12
                        Cheers Tempest, shaved 7 lines of code off, and is much easier to remember then the TreeBuilder method for future use.

                        Comment

                        • Tempest
                          Too lazy to set a custom title
                          • May 2004
                          • 10217

                          #13
                          If you're going to do quite a bit of Perl, I'd recomend you get and read this book http://oreilly.com/catalog/9780596520106/ and then the rest in the series... You might also want to check out this downloadable book http://www.perl.org/books/beginning-perl/ or perhaps this site http://www.perltutorial.org/

                          Comment

                          • Angry Jew Cat - Banned for Life
                            (felis madjewicus)
                            • Jul 2006
                            • 20368

                            #14
                            Originally posted by Tempest
                            If you're going to do quite a bit of Perl, I'd recomend you get and read this book http://oreilly.com/catalog/9780596520106/ and then the rest in the series... You might also want to check out this downloadable book http://www.perl.org/books/beginning-perl/ or perhaps this site http://www.perltutorial.org/
                            i forgot my llama during my last move, but i agree, its a great book. i wish i had it with me

                            Comment

                            Working...