b280889189
2013-09-12 11:02
采纳率: 100%
浏览 4.3k
已采纳

大神啊!如何用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 2013-09-13 08: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());
        }
    }
    
    已采纳该答案
    打赏 评论

相关推荐 更多相似问题