Xml Output From Html Page Using Web Scraping In Perl
Solution 1:
You just need to move your output into the first for
loop. Since you've an equal number of items in each of the three keys in $res
, you can just use $i
to access all of the individual items. You'll get the three values that belong to each other with your iteration from $i
.
for my $i (0 .. $#{$res->{renners}}) {
print <<"XML";
<PropertyList>
<Property>
<Name>$res->{renners}[$i]</Name>
<ReturnValue>$res->{landrenner}[$i]</ReturnValue>
<domversion>$res->{dom}[$i]</domversion>
</Property>
</PropertyList>
XML
}
I changed the print
statements to use a HERE doc because it is more easily readable. I also changed the line my $res = $teamsdata->scrape(URI->new($urlToScrape));
to my $res = $rennersdata->scrape(URI->new($urlToScrape));
because $teamsdata
was not declared.
Solution 2:
I realize this is not exactly what you are looking for, but take a look at HTML::Element. It has a as_XML method which you can use to convert the HTML tree into XML. HTH.
Solution 3:
Try this: Simply rearrange the print statements:
print "<PropertyList>\n";
for my $i (0 .. $#{$res->{renners}}) {
print "<Property>\n";
print "<Name> ";
print $res->{renners}[$i]; print "\n";
print "</Name>"; print "\n";
for my $j (0 .. $#{$res->{landrenner}}) {
print "<ReturnValue>\n";
print $res->{landrenner}[$j];print "\n";
print "</ReturnValue>\n";
}
for my $k (0 .. $#{$res->{dom}}) {
print "<domversion>\n";
print $res->{dom}[$k];print "\n";
print "</domversion>\n";
}
print "</Property>\n";
}
print "</PropertyList>\n";
Element?
I have a table and I need the cells to have an element posi…
Here's a js fiddle of what I currently have, I am tryin…
So I have a few pictures that I want to randomly generate o…
This is my first question. I usually try to research these …
Right Floated Element Disappears When Using Columns In Firefox
I am using an ol element with column-count and column-gap p…
Setting Link Href From Child Image Src Using JQuery
I am using .wrap() to create a link around each image withi…
How To Limit The Html Table Records In Each Page
I am populating a table in my jsp which has more than 20 re…
I want to show countdown in each of my divs. Right now I ge…
Retain Dynamically Created DropDown List's Selected Value On Event Window.history.back()- JavaScript
Can use the below question as a reference to explain the co…
|
Post a Comment for "Xml Output From Html Page Using Web Scraping In Perl"