Apache HttpClient 4和JavaScript [英] Apache HttpClient 4 And JavaScript

查看:327
本文介绍了Apache HttpClient 4和JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Apache HttpClient访问网页。我想点击链接,但链接是javaScript,如何处理点击JavaScript链接并按照网址重定向?

I Use Apache HttpClient to Access a webpage . i want to click on a link but the link is javaScript , how can i process click on a javascript link and follow url redirection ?

示例javascript和html代码:

sample javascript and html code :

<a href="javascript:send(32023, 'YGHN_JKM', '8LMK');"> link</a>


function send(content_id, fic, cgRate) {
        var params = new Hash();
        params.set('content_id', content_id);
        params.set('tool', fic);
        params.set('cgRate', cgRate);

        new Ajax.Updater('return', '/mypkg/tools', {
            method: 'post',
            parameters: params,
            evalScripts: true,
            onInitialize: new Effect.Appear('loader', {duration: 0.0}),
            onComplete: new Effect.Fade('loader', {duration: 1.2})
        });
}


推荐答案

看起来像你的页面正试图使用​​AJAX来获取链接。仅用vanilla HTTPClient来模拟这种行为是很困难的。 HTTPClient用于原始HTTP通信,而不是浏览器仿真。相反,我建议使用类似于HtmlUnit的东西,它可以模拟浏览器并在页面上执行JavaScript: http://htmlunit.sourceforge.net/

It looks like the page you are trying to get to uses AJAX to fetch the link. It would be difficult to emulate this behavior with just vanilla HTTPClient. HTTPClient is for "raw" HTTP communication, and not browser emulation. Instead, I recommend using something akin to HtmlUnit, which can emulate a browser and execute the JavaScript on the page: http://htmlunit.sourceforge.net/

HtmlUnit具有相当不错的JavaScript支持,但并不完美。如果您需要依赖100%完美的浏览器模拟,您需要使用浏览器自动化框架,例如Selenium: http://seleniumhq.org/

HtmlUnit has rather good JavaScript support, but it is not perfect. If you need to rely on 100% perfect browser emulation, you need to use a browser automation framework such as Selenium: http://seleniumhq.org/

这篇关于Apache HttpClient 4和JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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