我一直在使用WWW::Mechanize perl模块尝试登录到一个需要Steam身份验证的网站。到目前为止,我已经成功地将它转到了登录页面,但是一旦我提交了我的表单,它似乎就完全不起作用了。提交表单后,页面内容不会发生变化,就好像我登录失败一样,它会让我重试。我已经搜索了几个小时,我尝试了许多不同的组合来设置表单框和提交文本,但都不起作用。由于某些原因,我几乎没有发现关于检查Mechanize是否可以查看登录是否有效的内容。也许我的搜索词不好。
这是我到目前为止得到的代码。这应该做的是转到tf2wh的登录表单,重定向到Steam登录页面,填写user/pass,单击按钮,然后返回到tf2wh,并将登录会话保存在cookies中。但是,唯一有效的部分是初始登录重定向。
#!/usr/bin/perl
use strict;
use warnings;
use WWW::Mechanize;
my $user = "my_username";
my $pass = "my_password";
my $uri = 'http://www.tf2wh.com/?login';
my $cookies = 'cookies.txt';
my $agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)';
my $mechanize = WWW::Mechanize->new(
    agent => $agent,
    cookie_jar => {},
    autosave => 1,
    ignore_discard => 1);
$mechanize->add_header(
    "Connection" => "keep-alive",
    "Keep-Alive" => "115");
$mechanize->get( $uri );
$mechanize->success or die "Could not fetch login page.\n";
#One of many different forms I've tried
$mechanize->form_name('login');
$mechanize->set_visible($user, $pass);
$mechanize->click();
$mechanize->follow_link();
$mechanize->success or die 'Could not login.';
print "Logged in successfully! Trying to look at TF2WH now.\n";
#Test to see if we get the "You need to login" message
$mechanize->get('http://www.tf2wh.com/item.php?id=6011;6;78e2c5962db56a60f7c143a12875f3b6');
print "Fetched\n";
if($mechanize->text() =~ m{Handy Hint:})
{
    print "Failed to login.\n";
}
else
{
    print "Up and running!";
}发布于 2012-11-20 04:19:13
您可能需要传播一些steam headers。
单点登录解决方案充满了怪癖。
你可能会在steam上找到一个开发人员指南,它描述了如何在“你的游戏”中使用他们的authn/authz系统。
如果你不走运,他们已经把它们都打包成二进制对象了。如果你幸运的话,他们会确切地告诉你如何传播登录信息。
https://stackoverflow.com/questions/13437317
复制相似问题