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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:07:48+00:00 2026-06-01T15:07:48+00:00

I have the following code to access a HTML table. my $table = $tree->look_down(_tag

  • 0

I have the following code to access a HTML table.

my $table = $tree->look_down(_tag => "table", id => "moduleDetail");

however the text is coming down not formatted, because the web page uses the tables borders to divide certain pieces of text. So its coming down something like this, “mathematics for computingJordanstown” with jordanstown being I assume in the next cell. here is the code that i am using,

my @array; 
my $tree = HTML::TreeBuilder->new_from_content($mech->content);  
my $table = $tree->look_down(_tag => "table", id => "moduleDetail");




    for ($table ->look_down(_tag => 'tr')) {

                push(@array,$_->as_text());

    }

    foreach(@array){
           print $_, " ";
                    }
$tree->delete();

Note i tried to separate the text using and array but no luck? any pointers. 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-06-01T15:07:49+00:00Added an answer on June 1, 2026 at 3:07 pm

    Using HTML::TreeBuilder::XPath

    I suggest using the Perl module HTML::TreeBuilder::XPath for this. It should give you exactly what you want.

    From the documentation, I believe your code would look like this using the XPath module

    my $tree = HTML::TreeBuilder::XPath->new_from_content($mech->content);
    my @trArray = $tree->findnodes_as_string( '//table[@id="moduleDetail"]/tr/td');
    $tree->delete();
    

    For more information on XPath see http://www.w3schools.com/xpath/.

    Using HTML::TreeBuilder

    If you want to stick with using HTML::TreeBuilder, then you will need to do the following

    my $tree = HTML::TreeBuilder->new_from_content($mech->content);  
    my $table = $tree->look_down(_tag => "table", id => "moduleDetail");
    for ($table->look_down(_tag => 'td')) {
      push(@array,$_->as_text());   
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following scenario. The client code only has access to FooHandler, not
In the following code, it seems class C does not have access to A's
I have a following code in my html file and i want to access
I have the following code, that should remove the access of users from a
I have the following code which works perfectly, but I want to allow access
How do I access user preferences in Firefox? I have the following code: var
I was using the following code to retrieve HTML snippets from a database table
I have the following code, and I am not sure why when I role
Suppose I have the following html: var testString = ' <span id='id'> <div> <table>
I have the following JS code for ZeroClipBoard : onComplete: function(item) { var text=

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.