Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Oh sorry, here is the full code (I thought a snippet would be more clear in that case). This is everything from the folder, the 4 html pages and the perl code.

mech.pl

#!/usr/bin/perl use strict; use warnings; use WWW::Mechanize; use WWW::Mechanize::TreeBuilder; my $mech = WWW::Mechanize->new(); WWW::Mechanize::TreeBuilder->meta->apply($mech); $mech->get('file:///home/example/path/index.html'); die "Cannot open file: ", $mech->response->status_line unless $mech->success; my @list = $mech->look_down(_tag => "a", class => "links); foreach (@list) { my $url = "file:///home/example/path/"; $url = $url . $_->attr("href"); print $_->as_text(), " - ", $url, "\n"; $mech->get($url); $mech->back(); }

index.html

<html> <head> <title>Web Scraper Testing Grounds</title> <style> .links { font-family: Sans-Serif; } .spans { font-family: Serif; } .trs { border: 1px solid; } </style> </head> <body> <h1>Test Page for WWW::Mechanize scraping</h1> <table> <tr class="trs"> <td><a href="s1.html" class="links">S1 Link Content</a></td> <td><span class="spans">Page S1</span></td> </tr> <tr class="trs"> <td><a href="s2.html" class="links">S2 Link Content</a></td> <td><span class="spans">Page S2</span></td> </tr> <tr class="trs"> <td><a href="s3.html" class="links">S3 Link Content</a></td> <td><span class="spans">Page S3</td> </tr> </table> </body> </html>

s1.html

<html> <head></head> <body> <h1>This is the S1 page, first in set</h1> </body> </html>

s2.html

<html> <head></head> <body> <h1>This is the S2 page, second in set</h1> </body> </html>

s3.html

<html> <head></head> <body> <h1>This is the S3 page, third and final</h1> </body> </html>

When I try and run the code, this is the output I get

mdro79@mycpu$ ./mech.pl S1 Link Content - file:///home/example/path/s1.html Use of uninitialized value in concatenation (.) or string at ./scrMe.p +l line 31. Use of uninitialized value $tag in string eq at /usr/local/share/perl/ +5.14.2/HTML/Element.pm line 1109. Use of uninitialized value $tag in string eq at /usr/local/share/perl/ +5.14.2/HTML/Element.pm line 1109. - file:///home/example/path/ Use of uninitialized value in concatenation (.) or string at ./scrMe.p +l line 31. Use of uninitialized value $tag in string eq at /usr/local/share/perl/ +5.14.2/HTML/Element.pm line 1109. Use of uninitialized value $tag in string eq at /usr/local/share/perl/ +5.14.2/HTML/Element.pm line 1109. - file:///home/example/path/

In reply to Re^2: WWW::Mechanize::TreeBuilder and WWW::Mechanize. Following links but can't return without error by mdro79
in thread WWW::Mechanize::TreeBuilder and WWW::Mechanize. Following links but can't return without error by mdro79

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (3)
    As of 2014-07-29 08:27 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (211 votes), past polls