大神們,我現在想做一個東西,就是要在百度網盤上下載東西,手動下載的時候要點擊兩個按鈕,我用程序怎麼實現這兩次點擊呢?應該向著哪個方向解決這個問題呢,神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;
}
哎,哥們搞定了,後來者借鑒下吧,用的是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());
}
}