Hi,

I am trying to automate data scraping of a well know router which has not SNMP services. It needs to answer a basic authentication challenge which starts with this request:

but with WWW::Mechanize::Firefox, we do not seem to build this WWW-Authenticate response...

following the examples in... https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsILoginManager/Using_nsILoginManager I use this code:
use WWW::Mechanize::Firefox; use File::Temp qw/ :seekable /; my $url = 'http://192.168.1.1/'; my $formSubmitURL; my $httprealm = 'Default: admin/1234'; my $username = 'admin'; my $password = '1234'; my $res; my $hostname = $url; (my $u = "$url") =~ s!/$!!; my $mech = eval { WWW::Mechanize::Firefox->new( autodie => 0 , launch => '/usr/bin/firefox' || system(qq(which firefox) +) , autoclose => 0 , activate => 1 # bring the tab to the foreground , log => [qw[debug]] ) }; my $nsILoginManager = $mech->repl->expr(<<'JS'); Components.classes["@mozilla.org/login-manager;1"] .getService(Components.interfaces.nsILoginManager) JS my $logins = $nsILoginManager->findLogins({}, $url, $formSubmitURL, $h +ttprealm); my $count = $logins->{length}; my $nsILoginInfo; unless($count) { $nsILoginInfo = $mech->repl->expr(<<"JS"); var nsILI = new Components.Constructor( "\@mozilla.org/login-manager/loginInfo;1" , Components.interfaces.nsILoginInfo , "init" ); new nsILI("$hostname", null, "$httprealm", "$username", "$password +", "", "") JS # in resource://gre/components/nsLoginManager.js $res = $nsILoginManager->addLogin($nsILoginInfo); } (my $tpl_f = $url) =~ s/.*\/\///g; $tpl_f =~ s/\/.*//g; $tpl_f .= '_XXXXXX'; my $temp_p = File::Temp->newdir(TEMPLATE => $tpl_f, OPEN => 0); my %attr = (':content_file' => $temp_p->dirname . '.html', no_cache => + 1); $res = $mech->get($url, %attr);

but I always get this response ...

$mech->content '<html><head></head><body>WWW::Mechanize::Firefox</body></html>'
which is the first page.

Whereas remarkably, the file... "" $temp_p->dirname . '.html' "", contains the routers starting page:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://ww +w.w3.org/TR/html4/frameset.dtd"> <html><head><meta http-equiv="Content-Type" content="text/html; chars +et=utf-8"> <title>Some Technology</title></head>(.v.)<noframes><body></body></no +frames></html>
  • what is the way to automatically build this basic authentication challenge response with WWW::Mechanize::Firefox ?
  • thx.

    In reply to WWW-Authenticate with [WWW::Mechanize::Firefox] by ptizoom

    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.