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
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
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