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

  • Home
  • SEARCH
  • 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 9267141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:28:53+00:00 2026-06-18T14:28:53+00:00

I have an HTML file with several tables (all tables have same number of

  • 0

I have an HTML file with several tables (all tables have same number of columns and same column names). The tables are separated by other HTML tags.

For each row in each table, I would like to change the value of cell 1 and cell 3.

This what I have so far (thanks to @depesz):

#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use open qw( :std :utf8 );

use HTML::TreeBuilder;

my $input_file_name = shift;

my $tree = HTML::TreeBuilder->new();
$tree->parse_file( $input_file_name ) or die "Cannot open or parse $input_file_name\n";
$tree->elementify();

my @tables = $tree->find_by_tag_name( 'table' );
for my $table (@tables) {
    foreach my $row ($table->find_by_tag_name('tr')) {
        foreach my $column ($table->find_by_tag_name('td')) {
             # how do I change the text of first and 3rd column text to "removed"
        }
    }
}

print $tree->as_HTML();
exit;

It works great for iterating through all the rows in the HTML file. I’m just not sure how to do the last bit of changing the text in columns 1 and 3.

  • 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-18T14:28:54+00:00Added an answer on June 18, 2026 at 2:28 pm

    The HTML::TreeBuilder::XPath module allows much more convenient access to the HTML nodes in the document.

    Take a look at this program for example. It seems to do what you need.

    use strict;
    use warnings;
    
    use HTML::TreeBuilder::XPath;
    
    my $tree = HTML::TreeBuilder::XPath->new_from_file('anon.html');
    
    for my $table ($tree->findnodes('//table')) {
      my $row = 0;
      for my $tr ($table->findnodes('//tr')) {
        $row++;
        for my $td ($tr->findnodes('td[position() = 1 or position() = 3]')) {
          $td->delete_content;
          $td->push_content("name$row");
        }
      }
    }
    
    print $tree->as_HTML('<>&', '  ');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large HTML file (In ASP.NET) that has several smaller ... tags
I have an HTML page with several iframes, each pointing to a text file
I'm trying to have a script automatically transform an xml file into several html
I have html-file. I have to replace all text between this: [%anytext%]. As I
I have an html file and i need to generate a list of all
I have a common HTML header file which I use in several PHP files.
I have a html file like following: <form action=/2811457/follow?gsid=3_5bce9b871484d3af90c89f37 method=post> <div> <a href=/2811457/follow?page=2&amp;gsid=3_5bce9b871484d3af90c89f37>next_page</a> &nbsp;<input
I have an HTML file and i would like to parse through it using
I have following html file (1.html) and once I open it in my browser
I have a .html file with some scripts in it. Works fine on localhost

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.