简体   繁体   English

如何在 Perl 中操作 Javascript 网站

[英]How to manipulate Javascript websites in Perl

I have been asked to automate the logging into a webapp(what I assume to be one, that runs a lot of.aspx and.js scripts) that, currently, can only run in IE.我被要求自动登录到一个 webapp(我假设是一个,它运行很多 .aspx 和 .js 脚本),目前只能在 IE 中运行。 Now i am programming in Perl and have tried to use Win32::IE::Mechanize to run the IE browser and log in. What i did was try an extract all the forms from the webapp, and given the users information, fill out the required forms, but this is where the problem arises, when I try and run the subroutine no forms appear......现在我在 Perl 编程并尝试使用 Win32::IE::Mechanize 运行 IE 浏览器并登录。我所做的是尝试从 webapp 中提取所有 forms,并给出用户信息,填写需要forms,但这是问题出现的地方,当我尝试运行子程序时没有出现forms......

So then I transitioned into WWW::Mechanize and used the post subroutine(from LWP::UserAgent) which solved the problem for the most part.于是我过渡到 WWW::Mechanize 并使用了 post 子程序(来自 LWP::UserAgent),它在很大程度上解决了这个问题。 Now i've run into a problem in the response, from the server, I get this script as the content of the response and I don't know what to do with it.现在我在响应中遇到了问题,从服务器,我得到这个脚本作为响应的内容,我不知道该怎么处理它。

So my question is: Using Perl how can I go about to manipulate a Javascript functions in a website?所以我的问题是:使用 Perl 我如何在 go 中操纵 Javascript 功能在网站上? Would that even be a valid solution to the problem?这甚至是解决问题的有效方法吗?

I am open to writing this in other programming languages as well.我也愿意用其他编程语言写这个。 Thanks in advance for the help!在此先感谢您的帮助! (So that I can fully log in to the webapp) (这样我就可以完全登录webapp了)

Update : The content of the response:更新:响应的内容:

 var msgTimerID;

 var strForceLogOff = "false";

 function WindowOnLoad(){

    if ("false" == "true" && "false" == "false") 
        MerlinSystemMsg("",64);

    if ("false"=="true") 
        msgTimerID = window.setInterval("MerlinSystemMsg(10095,64)", 300000,'javascript');

 }

 function MyShowModal(){

     showModalDialog("", window, strFeatures);}

 function clearMsgInterval(){

    window.clearInterval(msgTimerID);

 }

 function WindowOnUnLoad(){

     if(top.frames(0).document.getElementById("OPMODE").value =="LOGOFF"){

         strFeatures = "width=1,height=1,left=1000,top=1000,toolbar=no,scrollbars=no,menubar=no,location=no,directories=no,status=yes,resizable=1";

         window.open("ForceLogOff.aspx","forcelogout",strFeatures);

     }

 }

 window.onbeforeunload = WindowOnUnLoad;

 window.onload = WindowOnLoad;

There is also this Frame Title that has the src:还有这个带有src的框架标题:

FRAME TITLE="Service Desk Express Navigator" SRC="options_nailogo.aspx" MARGINWIDTH=0 MARGINHEIGHT=0 NORESIZE scrolling=no FRAME TITLE="Service Desk Express Navigator" SRC="options_nailogo.aspx" MARGINWIDTH=0 MARGINHEIGHT=0 NORESIZE scrolling=no

Trying to emulate the browser with a fully functioning JS engine is going to be a mighty big task.尝试使用功能齐全的 JS 引擎来模拟浏览器将是一项艰巨的任务。 Instead, I'd suggest that you just try to emulate the actual interaction with the web site and not care what HTML/JS is actually sent back.相反,我建议您只尝试模拟与 web 站点的实际交互,而不关心实际发回的 HTML/JS 是什么。 Your server side code doesn't care how the HTTP submissions take place, only that they do.您的服务器端代码不关心 HTTP 提交是如何发生的,只关心它们是如何发生的。 Admittedly this is more fragile if the forms change a lot, but at least you're not trying to implement a full browser.诚然,如果 forms 发生很大变化,这会更加脆弱,但至少您并没有尝试实现完整的浏览器。

So look at modules like LWP::UserAgen t, HTTP::Request and HTTP::Response .因此,请查看LWP::UserAgen t、 HTTP::RequestHTTP::Response等模块。

I'm copying and pasting my answer to your other duplicate question here (You should consider deleting one of these?)我在这里复制并粘贴我对您的另一个重复问题的回答(您应该考虑删除其中一个?)

That content is the website source:)该内容是网站来源:)

How WWW::Mechanize deals with FRAME SRC as a link: WWW::Mechanize 如何将 FRAME SRC 作为链接处理

Note that <FRAME SRC="..."> tags are parsed out of the the HTML and treated as links so this method works with them.请注意,<FRAME SRC="..."> 标记从 HTML 中解析出来并被视为链接,因此此方法适用于它们。

You'll want to use follow_link on that link.您需要在该链接上使用follow_link

As far as dealing with Javascript, there is support for a Firefox Add-on called MozRepl that you can use in conjunction with WWW::Mechanize::Firefox that I have used in the past to call Javascript code while crawling a page. As far as dealing with Javascript, there is support for a Firefox Add-on called MozRepl that you can use in conjunction with WWW::Mechanize::Firefox that I have used in the past to call Javascript code while crawling a page.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM