Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6093721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:35:36+00:00 2026-05-23T12:35:36+00:00

I need to read an html file and find a certain paragraph tag, with

  • 0

I need to read an html file and find a certain paragraph tag, with specific text in it. Once I find that tag, I then want the text from all the next tags until I find a table tag

Example:

<asdf>
</asdf>
<p>THE SIGNAL TO GET INFO</p>
    <something>some good stuff in here</something>
<p>something else</p>
<ul>
    <li>something good in here for sure</li>
    <li>this too</li>
</ul>
<table> I DON'T WANT THIS </table>

I can find the first Paragraph tag with HTML::TokeParser like this:

my $description = "";
my $tp = HTML::TokeParser->new(\$content) || die "Can't open: $!";

while (my $token = $tp->get_tag("p")) {
    my $paragraph = $tp->get_trimmed_text("/p");
    if ($paragraph =~ /On this page/) {
        until ((my $stop = $tp->get_token)->[1] eq "table") {
            if ( $stop->[0] eq "S" ) {
                print $stop->[0],"\n";
            }
        }
        return $description;
    } 
}

I’ve tried the above code… but something is desperately wrong with it, since it won’t even compile.

Thanks for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:35:36+00:00Added an answer on May 23, 2026 at 12:35 pm

    You probably want to call $tp->get_token, storing the data until you see ["S", "table"…]

    You say you couldn’t get this to work. Can you explain why/what you did see? Perhaps provide a full example for people to play with.

    Well, you didn’t provide example output, so I made some assumptions.

    #!/usr/bin/perl
    use HTML::TokeParser;
    
    my $content = "<asdf>
    </asdf>
    <p>THE SIGNAL TO GET INFO</p>
        <something>some good stuff in here</something>
    <p>something else</p>
    <ul>
        <li>something good in here for sure</li>
        <li>this too</li>
    </ul>
    <table> I DON'T WANT THIS </table>
    ";
    
    my $description = "";
    my $tp = HTML::TokeParser->new(\$content) || die "Can't open: $!";
    
    while (my $token = $tp->get_tag("p")) {
        my $paragraph = $tp->get_trimmed_text("/p");
        if ($paragraph =~ /THE SIGNAL TO GET INFO/) {
          while (my $toke = $tp->get_token)
          {
            last if ($toke->[1] eq "table");
    #       print "<$toke->[0]> <$toke->[1]> <$toke->[2]> <$toke->[3]> <$toke->[4]>\n";
    #       print " <".join("><",@{$toke->[3]}).">\n";
            if ($toke->[0] eq "T" ) {
                    my $text = $toke->[1];
                    $description .= $text;
            }
          }
          print $description;
          last;
        }
    }
    

    Produces:

        some good stuff in here
    something else
    
        something good in here for sure
        this too
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to read from a variety of different text files (I've some delimited
I need to read selected files, matching on the file name, from a remote
I need to read the value of a property from a file in an
I need to read the user's fingerprint from my application. What I really want
I have an html file named welcomemailtemplate.html and I need to convert that file
I need to find attribute values in an ASPX file using regular expressions. That
I need to read through the XML file that contains info but one at
I need a plain text representation of an arbitrary HTML file (e.g., a blog
I have an XML file containing some scientific text that I want to display
I am doing a project wherein I need to read an HTML file and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.