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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:37:57+00:00 2026-06-18T03:37:57+00:00

Is it possible to have an xml output from webpage using web::scraper in perl.

  • 0

Is it possible to have an xml output from webpage using web::scraper in perl. as an example, My html looks like follows(I took some part of html from URL):

   > <table class="reference">
    >     <tr>
    >     <th width="23%" align="left">Property</th>
    >     <th width="71%" align="left">Description</th>
    >     <th style="text-align:center;">DOM</th>
    >     </tr>
    >     <tr>
    >       <td><a href="prop_node_attributes.asp">attributes</a></td>
    >       <td>Returns a collection of a node's attributes</td>
    >       <td style="text-align:center;">1</td>
    >     </tr>
    >     
    >     <tr>
    >       <td><a href="prop_node_baseuri.asp">baseURI</a></td>
    >       <td>Returns the absolute base URI of a node</td>
    >       <td style="text-align:center;">3</td>
    >     </tr>
    >     <tr>
    >       <td><a href="prop_node_childnodes.asp">childNodes</a></td>
    >       <td>Returns a NodeList of child nodes for a node</td>
    >       <td style="text-align:center;">1</td>
    >     </tr>
    >     <tr>
    >       <td><a href="prop_node_firstchild.asp">firstChild</a></td>
    >       <td>Returns the first child of a node</td>
    >       <td style="text-align:center;">1</td>
    >     </tr>
    >     <tr>
    >       <td><a href="prop_node_lastchild.asp">lastChild</a></td>
    >       <td>Returns the last child of a node</td>
    >       <td style="text-align:center;">1</td>
    >     </tr>
    >     <tr>
    >       <td><a href="prop_node_localname.asp">localName</a></td>
    >       <td>Returns the local part of the name of a node</td>
    >       <td style="text-align:center;">2</td>
    >     </tr>
    >     <tr>
    >       <td><a href="prop_node_namespaceuri.asp">namespaceURI</a></td>
    >       <td>Returns the namespace URI of a node</td>
    >       <td style="text-align:center;">2</td>
    >     </tr>
    >     <tr>
    >       <td><a href="prop_node_nextsibling.asp">nextSibling</a></td>
    >       <td>Returns the next node at the same node tree level</td>
    >       <td style="text-align:center;">1</td>
    >     </tr>
    >     <tr>
    >       <td><a href="prop_node_nodename.asp">nodeName</a></td>
    >       <td>Returns the name of a node, depending on its type</td>
    >       <td style="text-align:center;">1</td>
    >     </tr>
    >     <tr>
    >       <td><a href="prop_node_nodetype.asp">nodeType</a></td>
    >       <td>Returns the type of a node</td>
    >       <td style="text-align:center;">1</td>
    >     </tr>
    >     <tr>
    >       <td><a href="prop_node_nodevalue.asp">nodeValue</a></td>
    >       <td>Sets or returns the value of a node, depending on its 
    >       type</td>
    >       <td style="text-align:center;">1</td>
    >     </tr>
    >     <tr>
    >       <td><a href="prop_node_ownerdocument.asp">ownerDocument</a></td>
    >       <td>Returns the root element (document object) for a node</td>
    >       <td style="text-align:center;">2</td>
    >     </tr>
    >     <tr>
    >       <td><a href="prop_node_parentnode.asp">parentNode</a></td>
    >       <td>Returns the parent node of a node</td>
    >       <td style="text-align:center;">1</td>
    >     </tr>
    >     <tr>
    >       <td><a href="prop_node_prefix.asp">prefix</a></td>
    >       <td>Sets or returns the namespace prefix of a node</td>
    >       <td style="text-align:center;">2</td>
    >     </tr>
    >     <tr>
    >       <td><a href="prop_node_previoussibling.asp">previousSibling</a></td>
    >       <td>Returns the previous node at the same node tree level</td>
    >       <td style="text-align:center;">1</td>
    >     </tr>
    >     <tr>
    >       <td><a href="prop_node_textcontent.asp">textContent</a></td>
    >       <td>Sets or returns the textual content of a node and its 
    >       descendants</td>
    >       <td style="text-align:center;">3</td>
    >     </tr>
    >     </table>

SO my perl code goes like:

    #!/usr/bin/perl
    use warnings;
    use strict;
    use URI;
    use Web::Scraper;

    # website to scrape
    my $urlToScrape = "http://www.w3schools.com/jsref/dom_obj_node.asp";

    my $rennersdata = scraper {
    process "table.reference > tr > td > a", 'renners[]' => 'TEXT';
 process "table.reference > tr > td:nth-of-type(2)", 'landrenner[]' => 'TEXT';
  process "table.reference > tr > td:nth-of-type(3)", 'dom[]' => 'TEXT';
     };

    my $res = $teamsdata->scrape(URI->new($urlToScrape));

for my $i (0 .. $#{$res->{renners}}) {
    print "<PropertyList>\n";
print "<Property>\n";
print "<Name> ";
    print $res->{renners}[$i];
    print "\n";
print "</Name>";
 print "\n";
print "</Property>\n";
print "</PropertyList>\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";
    }

when I am running the above code, I get all the output as follows:

<PropertyList>
<Property>
<Name>attributes</Name>
<Property>
<PropertyList>
<PropertyList>
<Property>
<Name>baseURI</Name>
<Property>
<PropertyList>
...
<ReturnValue>
Returns a collection of a node's attributes
</ReturnValue>
....
<domversion>
1
</domversion>
....

Is it possible that I can get the output as follows:

<PropertyList>
<Property>
<Name>attributes</Name>
<ReturnValue>Returns a collection of a node's attributes</ReturnValue>
<DOMVersion>1</DOMVersion>
</Property> 
</PropertyList>

How can I combine the above three forloops in order to get output as above?

Many 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-18T03:37:58+00:00Added an answer on June 18, 2026 at 3:37 am

    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.

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

Sidebar

Related Questions

I am using XmlSerializer to generate XML output for my class. Is it possible
I'm trying to generate an XML output from a type in C#. I'm Using
I have an XML string that looks like this: <Attributes> <ProductAttribute id=1> <ProductAttributeValue> <Value>a</Value>
I have a stream object, and I want to create and output xml using
Is it possible to have an AndroidManifest.xml and or resource files in a Jar
I have the following XML structure: <Main> <Node1>Definite</Node1> <Node2>Definite</Node2> <Node3>Definite</Node3> <Node4>Definite</Node4> <Node5>Definite</Node5> <Node6>Definite</Node6> <A>Possible</A>
Possible Duplicate: How to Deserialize XML document Suppose that I have a class that
Possible Duplicate: difference between WCF Services and Web Services and REST Service I have
I have a class that consume an XML file and produce text output based
Is it possible from this example table: CREATE TABLE #Actions(EmployeeId INT,EmployeeName VARCHAR(100),ActionStart TIME,ActionEnd TIME,Type

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.