bennierounder:

Looking at your code, there are a couple problems. The one that stands out the most is that you're getting a "Use of uninitialized value" message from your second print loop. That's happening because you're pulling values out of your @urls array that don't exist. You're seeing this because you're looping from 0 to 9 in your printout loop, no matter how many URLs are in the loop. I'd suggest you instead do something like this:

# Let's do this up to 10 times, but only as long as we have URLs while ($count < 10 and @urls) { # Choose a random URL from the list, and remove it from the list my $url_index = int(@urls * rand); my $source = splice @urls, $url_index, 1; # continue normally getstore($source, "web/$count.html"); print URLMAP "$count\n$source\n"; $count++; }

Fixes include:

  1. single quotes in your getstore() call would not replace $count with a value, but instead use the string '$count'.
  2. we remove each url from the list after use, so you don't reprocess any individual url.
  3. we stop the list when you (a) run out of URLs in the list, or (b) have processed 10 URLs.

This ought to remove the unsightly warnings you're getting.

The bug that's currently biting you, though, is that you don't have any URLs in your list. As you should see, you're printing each URL when you add them to your list, but your code isn't printing any URLs. That's because you're trying to find URLs in your $url string instead of your $html string. Since there are no URLs in https://google.com that are terminated with a quote or right angle bracket, your list comes up empty.

...roboticus

When your only tool is a hammer, all problems look like your thumb.


In reply to Re: First Web Crawl Task by roboticus
in thread First Web Crawl Task by bennierounder

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.