为什么我的 WWW::Mechanize 无法提交 PayPal 表单?
我尝试过的任何方法都无法使我的代码正确提交。其他人能解决这个问题吗?
#!/usr/bin/perl
use WWW::Mechanize;
my $user = '[email protected]';
my $pass = 'hackswipe';
# Test account; don't worry
my $browser = WWW::Mechanize->new();
$browser->get("https://www.paypal.com/");
$browser->form_with_fields("login_email", "login_password");
$browser->field("login_email", $user);
$browser->field("login_password", $pass);
$browser->submit_form();
$browser->get("https://www.paypal.com/us/cgi-bin/webscr?cmd=_profile-api-add-direct-access");
##### Help here ---> Trying to submit form with default option selected #####
my $html = $browser->content;
print $html;
Nothing I've tried can get my code to submit correctly. Can anyone else figure this out?
#!/usr/bin/perl
use WWW::Mechanize;
my $user = '[email protected]';
my $pass = 'hackswipe';
# Test account; don't worry
my $browser = WWW::Mechanize->new();
$browser->get("https://www.paypal.com/");
$browser->form_with_fields("login_email", "login_password");
$browser->field("login_email", $user);
$browser->field("login_password", $pass);
$browser->submit_form();
$browser->get("https://www.paypal.com/us/cgi-bin/webscr?cmd=_profile-api-add-direct-access");
##### Help here ---> Trying to submit form with default option selected #####
my $html = $browser->content;
print $html;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它对我有用,但是当涉及到调试网络抓取工具等时,您应该观察 HTTP 事务。添加起来非常容易,因为 WWW::Mechanize 是一个 LWP::UserAgent 子类:
现在您可以看到您发送的内容以及 PayPal 发回的内容。
通常,您还可以使用各种 HTTP 嗅探工具,但这些工具仅适用于以明文形式发送的内容,因此您在这里运气不佳。
然而,在这种情况下,PayPal 就轮到你了。他们知道您正在使用脚本。我得到的部分输出是:
如果您想通过程序与 PayPal 交互,您需要 注册开发人员访问权限< /a>.
It works for me, but when it comes to debugging web scrapers, etc, you should watch the HTTP transaction. That's really easy to add since WWW::Mechanize is an LWP::UserAgent subclass:
Now you can see what you send and what PayPal sends back.
Often you can also use various HTTP sniffing tools, but those only work for things that you send in plaintext, so you're out of luck here.
In this case, however, PayPal is on to you. They know you are using a script. Part of the output I get is:
If you want to interact with PayPal through a program, you need to sign up for developer access.
我们不知道问题到底是什么。您阅读了常见问题解答吗?
它提供了有关如何调试 Mech 问题的建议。我要问的第一件事是表单是否使用 JavaScript。我敢打赌 PayPal 的页面就是这么做的。
We don't know what the problem is, exactly. Have you read the FAQ?
It gives suggestions on how to debug problems with Mech. The first thing I'd have to ask is if the form is using JavaScript. I'd bet a nickel that PayPal's pages are doing that.