473,396 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Help with WWW::Mechanize Module using Authentication

numberwhun
3,509 Expert Mod 2GB
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:

Expand|Select|Wrap|Line Numbers
  1.    use MIME::Base64;
  2.  
  3.     my $agent = WWW::Mechanize->new();
  4.     my @args = (
  5.         Authorization => "Basic " .
  6.             MIME::Base64::encode( USER . ':' . PASS )
  7.     );
  8.  
  9.     $agent->credentials( ADDRESS, REALM, USER, PASS );
  10.     $agent->get( URL, @args );
  11.  
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
Nov 27 '07 #1
1 5810
numberwhun
3,509 Expert Mod 2GB
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).

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3. use WWW::Mechanize;
  4. use File::Basename;
  5.  
  6. my $url = "http://stampalbums.com/worldwide_list.asp";
  7. my $tempfile = "temp.txt";
  8.  
  9. my $mech = WWW::Mechanize->new;
  10. $mech->get('http://stampalbums.com/worldwide_list.asp');
  11. $mech->submit_form(with_fields => {
  12.     USERNAME         => '*****',
  13.     PASSWORD        => '*****'
  14. });
  15.  
  16. #$mech->get($url, ':content_file' => $tempfile);
  17. $mech->get($url);
  18.  
  19. #Get all the tarbulls
  20. my @links = $mech->find_all_links(url_regex => qr/\.pdf/);
  21. my @urls = map { $_->[0] } @links;
  22.  
  23. print("Found ", scalar @urls, " files to download\n");
  24.  
  25. for my $url1 (@urls)
  26. {
  27.     my $filename = basename($url1);
  28.     print("$filename\n");
  29.     $mech->get($url1, ':content_file'=>$filename);
  30. }
  31.  
Regards,

Jeff
Nov 27 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
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...
4
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...
0
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...
1
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...
11
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"}...
3
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...
0
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...
1
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...
8
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
jinu1996
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...
0
tracyyun
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.