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

  • SEARCH
  • Home
  • 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 8753587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:27:22+00:00 2026-06-13T13:27:22+00:00

I am currently attempting to create a Perl webspider using WWW::Mechanize. What I am

  • 0

I am currently attempting to create a Perl webspider using WWW::Mechanize.

What I am trying to do is create a webspider that will crawl the whole site of the URL (entered by the user) and extract all of the links from every page on the site.

What I have so far:

use strict;
use WWW::Mechanize;

my $mech = WWW::Mechanize->new();

my $urlToSpider = $ARGV[0];
$mech->get($urlToSpider);

print "\nThe url that will be spidered is $urlToSpider\n";

print "\nThe links found on the url's starting page\n";

my @foundLinks = $mech->find_all_links();

foreach my $linkList(@foundLinks) {

    unless ($linkList->[0] =~ /^http?:\/\//i || $linkList->[0] =~ /^https?:\/\//i) {

        $linkList->[0] = "$urlToSpider" . $linkList->[0];
    }

    print "$linkList->[0]";
    print "\n";
}

What it does:

1. At present it will extract and list all links on the starting page

2. If the links found are in /contact-us or /help format it will add ‘http://www.thestartingurl.com’ to the front of it so it becomes ‘http://www.thestartingurl.com/contact-us’.

The problem:

At the moment it also finds links to external sites which I do not want it to do, e.g if I want to spider ‘http://www.tree.com’ it will find links such as http://www.tree.com/find-us.
However it will also find links to other sites like http://www.hotwire.com.

How do I stop it finding these external urls?

After finding all the urls on the page I then also want to save this new list of internal-only links to a new array called @internalLinks but cannot seem to get it working.

  • 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-13T13:27:22+00:00Added an answer on June 13, 2026 at 1:27 pm

    This should do the trick:

    my @internalLinks = $mech->find_all_links(url_abs_regex => qr/^\Q$urlToSpider\E/);
    

    If you don’t want css links try:

    my @internalLinks = $mech->find_all_links(url_abs_regex => qr/^\Q$urlToSpider\E/, tag => 'a');
    

    Also, the regex you’re using to add the domain to any relative links can be replaced with:

    print $linkList->url_abs();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to create a bookmarklet that will change the URL of the
I am currently attempting to create a bash script that will check inside of
I'm attempting to create an ASP.NET/C# page that runs a PowerShell script that will
I am attempting to create an application that will call a remote modem and
I am currently attempting to create a fairly basic web app that has the
I am attempting to create a manual build in Jenkins that will build a
I'm attempting to create Data Access Layer for my web application. Currently, all datatables
I'm playing with using Regex to modify Twitter posts. I'm currently attempting to trim
I currently have a deployed app (fortworth.herokuapp.com) that I am attempting to sort movies
I am attempting to create a wcf service that accepts any input (Action=*) and

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.