numberwhun 3,509
Recognized Expert Moderator Specialist
I am having an issue with understanding something in the WWW::Mechanize module. I have a website which I want to download a whole plethora of pdf files from. It is a site that I have paid to access and it is perfectly legal for me to download them, but there are FAR too many files to download by hand so I want to automate the process. The problem is, is that the site has a login page (see http://stampalbums.com/worldwide_list.asp).
I was looking at the page for How to get WWW::Mechanize to handle authentication, but it is a little vague on somethings.
I took the code that they have: -
use MIME::Base64;
-
-
my $agent = WWW::Mechanize->new();
-
my @args = (
-
Authorization => "Basic " .
-
MIME::Base64::encode( USER . ':' . PASS )
-
);
-
-
$agent->credentials( ADDRESS, REALM, USER, PASS );
-
$agent->get( URL, @args );
-
and tried to set it up. I created variables for USER, PASS, and URL. My questions is, what should ADDRESS and REALM be? Is ADDRESS the base url? (ie: stampalbums.com ) and the realm the rest of the address starting with the "/" after the base url? There is no explanation on either the link above or the LWP::UserAgent page, which is what is used with the 4 option version above.
Please, any assistance you can provide will be GREATLY appreciated. No, I am not going to say "URGENT" or "ASAP" as that is my issue, but I am just trying to get this done before I have to pay for another year. :-) You know how it is. If I can't get it working that quick, its only $20 / year.
Anywho, thanks in advance for any and all help you can give. I really appreciate it!!!
Regards,
Jeff
1 5834 numberwhun 3,509
Recognized Expert Moderator Specialist
Ok, I was actually able to figure this one out. It took a fair amount of research and some creative thinking, but I did it. The code below will log into the site and download ALL of the pdf files on the page. For my own security, I have removed my login and password from the code. (I am sure you understand why). -
use strict;
-
use warnings;
-
use WWW::Mechanize;
-
use File::Basename;
-
-
my $url = "http://stampalbums.com/worldwide_list.asp";
-
my $tempfile = "temp.txt";
-
-
my $mech = WWW::Mechanize->new;
-
$mech->get('http://stampalbums.com/worldwide_list.asp');
-
$mech->submit_form(with_fields => {
-
USERNAME => '*****',
-
PASSWORD => '*****'
-
});
-
-
#$mech->get($url, ':content_file' => $tempfile);
-
$mech->get($url);
-
-
#Get all the tarbulls
-
my @links = $mech->find_all_links(url_regex => qr/\.pdf/);
-
my @urls = map { $_->[0] } @links;
-
-
print("Found ", scalar @urls, " files to download\n");
-
-
for my $url1 (@urls)
-
{
-
my $filename = basename($url1);
-
print("$filename\n");
-
$mech->get($url1, ':content_file'=>$filename);
-
}
-
Regards,
Jeff
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Dariusz |
last post by:
Can anyone help me out on how to get this time dependent code to work. I
want it to display a greeting depending on the hour of the day (I'm trying
to convert my own Perl code to PHP with no luck on this one). I want it to
use the time of the local computer rather than the server.
Thanks
Dariusz
<?PHP
|
by: mattigiat |
last post by:
Sorry for being such a newbie in this respect, but here's my question:
I have Visual Studio, with VB6 ent., with msdn help installed. Is
there any way to downgrade to just using the VB5 help, on the VB6 app?
I too am not on board with "more help than you ever imagined, or
wanted" approach, and don't like msdn. I read dozens of postings last
night, with so many people remarking the msdn help format is too
distracting and unhelpful. I...
|
by: Lorenzo |
last post by:
I had to transfer an ASP Web Application (developed by another person) to a
different web server. It seems to work but not completely.
I have some problems with authentication: it is based on a username and a
password stored in a SQL Server's table. These data are requested via basic
authentication (not a IIS level but I think it is used to create the
authentication window in which put username and password). The problem is
that it...
|
by: JingleBEV |
last post by:
Hi all,
I don't seem to get this going, possibly lacking the knowledge of dao
recordset. I try to fill this Datagrid with the DAO.recordset, but it keeps
giving me the error 13 - datatype mismatch. Can somesone shed some light
please.
I define
rsDepartmentList as Dao.recordset
|
by: VB Programmer |
last post by:
PLEASE HELP....
I'm having trouble. In my login form after I've verified the
username/password are valid I do this:
Select Case iMyPrivilege
Case 0
Dim arrRoles() As String = {"guest"}
Context.User = New
System.Security.Principal.GenericPrincipal(User.Identity, arrRoles)
Case 1
| |
by: Steve Long |
last post by:
Hello,
can someone help me figure out how to do a couple of things here? I would
like to use the Uninstall method of the Win32_Product class and am having
trouble figuring this one out.
When I do a query with the following code, I get a ManagementException of
Invalid class:
ManagementScope ms = new ManagementScope(@"root\cimv2");
SelectQuery q = new SelectQuery("SELECT * From Win32_Product where
|
by: emiliano |
last post by:
Hey guys, i was just googling some information about how to use the ClientForm package with a page which requires HTTP basic authentication and i got here :P ... So here is the problem, lets see if anyone here can help me please solving this issue
First i open the protected page using the FancyURLopener which support the HTTP basic authentication and pass this object to the ParseResponse function so it parses the corresponding forms :P
...
|
by: Newbie |
last post by:
Hi all,
I'm hosted my ASP.NET 2.0 on an .NET 2.0 enabled shared hosting provider.
I tried the user registration page and it returns following error: "An error
has occurred while establishing a connection to the server".
Please click this link, just enter anything you want:
http://www.infoteknika.info/registration.aspx
The same form works perfectly on my development machine. I've checked that
the 'app_data' directory has been set/CHMOD...
|
by: NicolasG |
last post by:
I'm using the following code to send e-mail through python:
import smtplib
fromaddr = 'myMail@gmail.com'
toaddrs = 'myOtherMail@gmail.com'
subject = 'someting for subject !'
msg = 'This is body of the mail.'
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |