超级编辑:此方法将需要 WWW::Mechanize 但它允许您登录到您的网站然后获取 xml 页面。您将不得不更改评论中的一些内容。希望这可以帮助。
use strict;
use warnings;
use Data::Dumper;
use XML::Simple;
use WWW::Mechanize;
# Create a new instance of Mechanize
$bot = WWW::Mechanize->new();
# Create a cookie jar for the login credentials
$bot->cookie_jar(
HTTP::Cookies->new(
file => "cookies.txt",
autosave => 1,
ignore_discard => 1,
)
);
# Connect to the login page
$response = $bot->get( 'http://www.thePageYouLoginTo.com' );
# Get the login form
$bot->form_number(1);
# Enter the login credentials.
# You're going to have to change the login and
# pass(on the left) to match with the name of the form you're logging
# into(Found in the source of the website). Then you can put your
# respective credentials on the right.
$bot->field( login => 'thisIsWhereYourLoginInfoGoes' );
$bot->field( pass => 'thisIsWhereYourPasswordInfoGoes' );
$response =$bot->click();
# Get the xml page
$response = $bot->get( 'http://website/computers/computers_main/config.xml' );
my $content = $response->decoded_content();
my $parser = new XML::Simple;
my $data = $parser->XMLin($content);
print Dumper($data);
试一试。如上所述使用 LWP::Simple。它只是连接到页面并获取该页面的内容(xml 文件)并通过 XMLin 运行。
编辑:在 get $url 行添加了简单的错误检查。
Edit2:将代码保留在这里,因为如果不需要登录它应该可以工作。
use strict;
use warnings;
use Data::Dumper;
use XML::Simple;
use LWP::Simple;
my $parser = new XML::Simple;
my $url = 'http://website/computers/computers_main/config.xml';
my $content = get $url or die "Unable to get $url\n";
my $data = $parser->XMLin($content);
print Dumper($data);