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 6764273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:34:28+00:00 2026-05-26T14:34:28+00:00

I am building a HTML parser in Perl. I would like to know if

  • 0

I am building a HTML parser in Perl. I would like to know if the HTML element is an element without any sibilings.

Here is the HTML, I would like to parse :

<span class="bold1">A:</span> ELementA<br />
<span class="bold1">B:</span> <a href="mailto:admin" class="bold1">mailto:admin</a><br />
<span class="bold1">C </span> 01/12<br />
<span class="bold1">D:</span> ELementC<br />
<span class="bold1">E:</span> ElementD<br />
<span class="bold1">F:</span> ElementE<br />

How to check if the element is the end element.

I am getting the error :

Can't call method "as_text" without a package or object reference at 

Any idea what could be wrong ?

Here is the code snippet in Perl,

my $mech = WWW::Mechanize->new( autocheck => 1 );

eval 
{
    $mech->get($url);
};
if ($@) 
{
    print "Error connecting to URL $url \n";
    exit(0);
}

my $root = HTML::TreeBuilder->new_from_content(decode_utf8($mech->content));

my @PageSections = $root->look_down( 
            sub { 
                return (
                ($_[0]->tag() eq 'span' ) and 
                ($_[0]->attr('class')  =~ m/bold1/i) )

            }); 

my $temp2;
my $temp3;

for my $ps (@PageSections)
{
    #  my $temp1= $ps->right()->as_text;
    $temp2= $ps->as_text;

    my $temp3=ref $ps->right();
    # 
    print defined $temp3 ? "defined \n" : "not defined\n";
}

Thanks

  • 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-26T14:34:29+00:00Added an answer on May 26, 2026 at 2:34 pm

    It’s hard to tell without knowing more of your code, but I’m guessing @PageSections contains objects of some home brewed module, and that something happens there to make $_ point to something completely different. I’d go with

    for my $ps (@PageSections)
    {
        my $temp1= $ps->right()->as_text;
        my $temp2= $ps->as_text;
        print "$temp2  " . $temp1 . " \n";
    }
    

    instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a HTML template for my site and would like to have a
I am using LINQ-to-XML. I am building a small program that helps parse HTML.
I've put an html web resource on my contract form and would like to
how can I make a text box or any input form parse html? Im
I am building my own humble (x)html parser. All is ok, but some doctype
I'm building a simple shoutbox. Here's the html : <div id=shoutbox> <form method=post id=form
I'm building a HTML application to run in an Adobe AIR container, but the
I am building an HTML Gui builder and this involves round-tripping HTML pages from
Suppose you're building an HTML form and you want to have 2 or more
I am building some basic HTML code for a CMS. One of the page-related

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.