4

I am having trouble using the credentials agent for WWW:Mechanize to access and web scrape a site that requires NTLM authentication. I read online that the credentials agent requires 4 arguments: a base, realm, username and password. I'm not sure what to use for the base or realm so an example of these would be very helpful. When I run my code I get an error unauthorized on the line with the $url get. Any help would be appreciated

#!/usr/bin/perl
use strict;
use warnings;


use WWW::Mechanize;

use HTML::TokeParser;


my $url= shift || "mywebsite.com";

my $agent = WWW::Mechanize->new( autocheck => 1 );

$agent->credentials ( "proxy:port", '', 'domain/username', 'password' );

$agent->proxy(['https', 'http', 'ftp'], 'proxy:port');

$agent->get( $url );

print $agent->content();
  • 3
    This [link](http://www.perlmonks.org/?node_id=765651) has an example, and it also mentions that WWW::Mechanize must be v1.5.2, or later to use credentials – David Aug 13 '12 at 21:45

1 Answers1

1

It helps to read the documentation of the software you're working with. WWW::Mechanize overrides the credentials method so that it also just accepts username and password. These are eventually passed through to Authen::NTLM.

daxim
  • 39,270
  • 4
  • 65
  • 132
  • Ok thanks for the answer, so the credentials method should only have two arguments? username and password? – user1596292 Aug 14 '12 at 13:16
  • Yes, WWW::Mechanize's credential's method says just that ... http://search.cpan.org/~ether/WWW-Mechanize-1.73/lib/WWW/Mechanize.pm#$mech->credentials(_$username,_$password_) – hpavc Feb 09 '14 at 18:42