Perl - 提交 Javascript 操作到主机 [英] Perl - Submit Javascript action to host

查看:15
本文介绍了Perl - 提交 Javascript 操作到主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 Perl 构建一个 Spider,但遇到了一个问题:

I am building a Spider in Perl and have a problem:

我想抓取的网站使用 JavaScript 进行年龄验证,但我不知道如何在 Perl 中解决这个问题...?

The Site I want to spider uses a JavaScript for Age-Verification and I don't know how to get past this in Perl...?

脚本如下所示:

<script type = "text/javascript">

function set_age_verified(){

    new Request({

        method: "post",

        url: "/user/set_age_verified"

    }).send();

    $('age_verification').setStyles({visibility: 'hidden', display: 'none'});

    $('page_after_verification').setStyles({visibility: 'visible', display: 'block'});

    return false;

}

</script>

这里是 OnClick 事件:

And here the OnClick Event :

<a href="#" onclick="return set_age_verified();"><img src="http://example.com/age-verification-enter.gif" alt="ENTER"></a>

推荐答案

函数有两个作用.一种是向 URL/user/set_age_verified" POST 请求,另一种是更改某些 HTML 的显示可见性.

The function has two effects. One is to POST a request to the URL "/user/set_age_verified" and the other is to alter the display visibility of some HTML.

你的蜘蛛可以很容易地忽略第二个效果,但可能是第一个效果,通过转到服务器,设置服务器需要的一些 cookie 或服务器变量.

Your spider can easily ignore the second effect, but presumably the first effect, by going to the server, sets some cookie or server variable which the server will require.

您不必实际运行 javascript,只要服务器看到相同的 POST 数据即可.

You do not have to actually run the javascript, so long as the server sees the same POST data.

答案是让您的 Perl 脚本检测具有此 javascript 的页面,并调用 Perl 函数将数据发布到年龄验证 URL.

The answer is for your Perl script to detect pages which have this javascript, and to call a Perl function to POST the data to the age verification URL.

您必须记录返回的任何 cookie 或类似内容 - 不过,您的 HTTP 库可能会为您处理.

Any cookie or similar which is returned will have to be recorded by you - your HTTP library may take care of this for you though.

这篇关于Perl - 提交 Javascript 操作到主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆