为什么我的 WWW::Mechanize 无法提交 PayPal 表单?

发布于 2024-09-25 13:24:22 字数 820 浏览 3 评论 0原文

我尝试过的任何方法都无法使我的代码正确提交。其他人能解决这个问题吗?

#!/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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

毁梦 2024-10-02 13:24:22

它对我有用,但是当涉及到调试网络抓取工具等时,您应该观察 HTTP 事务。添加起来非常容易,因为 WWW::Mechanize 是一个 LWP::UserAgent 子类:

use WWW::Mechanize;

my $browser = WWW::Mechanize->new();

# See LWP::Debug
$browser->add_handler("request_send",  sub { shift->dump; return });
$browser->add_handler("response_done", sub { shift->dump; return });

现在您可以看到您发送的内容以及 PayPal 发回的内容。

通常,您还可以使用各种 HTTP 嗅探工具,但这些工具仅适用于以明文形式发送的内容,因此您在这里运气不佳。

然而,在这种情况下,PayPal 就轮到你了。他们知道您正在使用脚本。我得到的部分输出是:

<h2>Request API Credentials</h2>
</div>
<div id="messageBox"></div>
<div id="main"><div class="layout1"><form action="https://www.paypal.com/us/cgi-bin/webscr?dispatch=5885d80a13c0db1f8e263663d3faee8dc18bca4c6f47e633b393e284a5f8a8f8" class="">
<input type="hidden" name="cmd" value="_profile-api-add-direct-access"><input type="hidden" name="api_flow_origin" value=""><input type="hidden" name="show_switch" value="1"><input type="hidden" name="auth_type" value="ssl"><input type="hidden" name="api_username" value=""><input type="hidden" name="program_name" value=""><input type="hidden" name="program_id" value=""><input type="hidden" name="partner_name" value=""><input type="hidden" name="partner_id" value=""><input type="hidden" name="partner_code" value=""><p>API credentials consist of three elements:</p>
<ul>
<li>An API username</li>
<li>An API password</li>
<li>Either an API signature or an API SSL client-side certificate</li>
</ul>
<p>If you’re using a shopping cart or solution provider, ask whether you need an API signature or a certificate.</p>

如果您想通过程序与 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:

use WWW::Mechanize;

my $browser = WWW::Mechanize->new();

# See LWP::Debug
$browser->add_handler("request_send",  sub { shift->dump; return });
$browser->add_handler("response_done", sub { shift->dump; return });

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:

<h2>Request API Credentials</h2>
</div>
<div id="messageBox"></div>
<div id="main"><div class="layout1"><form action="https://www.paypal.com/us/cgi-bin/webscr?dispatch=5885d80a13c0db1f8e263663d3faee8dc18bca4c6f47e633b393e284a5f8a8f8" class="">
<input type="hidden" name="cmd" value="_profile-api-add-direct-access"><input type="hidden" name="api_flow_origin" value=""><input type="hidden" name="show_switch" value="1"><input type="hidden" name="auth_type" value="ssl"><input type="hidden" name="api_username" value=""><input type="hidden" name="program_name" value=""><input type="hidden" name="program_id" value=""><input type="hidden" name="partner_name" value=""><input type="hidden" name="partner_id" value=""><input type="hidden" name="partner_code" value=""><p>API credentials consist of three elements:</p>
<ul>
<li>An API username</li>
<li>An API password</li>
<li>Either an API signature or an API SSL client-side certificate</li>
</ul>
<p>If you’re using a shopping cart or solution provider, ask whether you need an API signature or a certificate.</p>

If you want to interact with PayPal through a program, you need to sign up for developer access.

黎歌 2024-10-02 13:24:22

我们不知道问题到底是什么。您阅读了常见问题解答吗?

perldoc WWW::Mechanize::FAQ

它提供了有关如何调试 Mech 问题的建议。我要问的第一件事是表单是否使用 JavaScript。我敢打赌 PayPal 的页面就是这么做的。

We don't know what the problem is, exactly. Have you read the FAQ?

perldoc WWW::Mechanize::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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文