2 b280889189 b280889189 于 2013.09.12 19:02 提问

大神啊!如何用HTTP请求调用网页中的脚本啊!神er

大神们,我现在想做一个东西,就是要在百度网盘上下载东西,手动下载的时候要点击两个按钮,我用程序怎么实现这两次点击呢?应该向着哪个方向解决这个问题呢,神er。

我看了下html代码,里面是调用的JS,JS又调用了别的什么玩意,这个是点击第一个按钮的click触发代码,第二个按钮在静态的HTML上找不到啊,神啊,出来吧!!
function(B){
var A=disk.util.ViewShareUtils.viewShareData,_=null;
try{
=$.parseJSON(A);
}
catch(C)
{}
if(
!=null)
{
disk.util.ViewShareUtils.downloadShareFile([_],$(this).attr("href"));
}
else{
disk.util.ViewShareUtils.useToast(disk.ui.Toast.MODE_CAUTION,"\u670d\u52a1\u5668\u9519\u8bef\uff0c\u8bf7\u7a0d\u5019\u91cd\u8bd5",false);
}
B.preventDefault();
return false;
}

1个回答

b280889189
b280889189   2013.09.13 16:39
已采纳

哎,哥们搞定了,后来者借鉴下吧,用的是HtmlUnit,下面是在百度输入“小时代”然后取回结果的代码。

import java.io.IOException;
import java.net.URL;

import com.gargoylesoftware.htmlunit.AjaxController;
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.WebRequest;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
import com.gargoylesoftware.htmlunit.html.HtmlTextInput;

public class Connect
{
    public static void main(String[] rgs)
    {
        WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3_6);
        webClient.setJavaScriptEnabled(true);
        HtmlPage page = null;
        HtmlPage pageResponse = null;

        AjaxController ajaxController = new NicelyResynchronizingAjaxController();

        try
        {
            WebRequest request = new WebRequest(new URL("http://www.baidu.com"));
            webClient.setAjaxController(ajaxController);
            webClient.waitForBackgroundJavaScript(10000);
            page = webClient.getPage(request);
            ajaxController.processSynchron(page, request, true);

        }
        catch(IOException e)
        {
            e.printStackTrace();
        }
        HtmlForm form = page.getFormByName("f");
        HtmlTextInput kw = form.getInputByName("wd");
        kw.setText("小时代");
        HtmlSubmitInput formSubmit = form.getInputByValue("百度一下");
        try
        {
            pageResponse = formSubmit.click();
        }
        catch(IOException e)
        {
            System.out.println("Form Button" + e.getMessage());
        }
        System.out.println(pageResponse.asXml());
    }
}
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!