我有一个网站,为特定链接调用__doPostBack。我已经尝试加载链接加载的页面,但手动输入POST数据并手动设置__EVENTTARGET和__EVENTARGUMENT,但我一直收到错误页面..如果有人使用过JSOUP库并找到了解决此问题的方法请让我知道。以下是使用POST数据调用网站的代码:
Connection.Response res = Jsoup.connect("https://parentaccess.ocps.net/Progress/ProgressSummary.aspx?T=2").data(target.substring(0,target.length()-5)+"txtClass_DBID",dBID).data("__LASTFOCUS","").data("__EVENTVALIDATION", eventValidation).data("__VIEWSTATE", viewState).cookie("ASP.NET_SessionId", cookie).data("__EVENTTARGET",target).data("DropDownListGradingPeriod","3").data("__EVENTARGUMENT","").header("Content-Type","text/html; charset=utf-8").header("Connection", "keep-alive").header("Cache-Control", "private").method(Method.POST).execute();
Document doc = res.parse();
Document doc2 = Jsoup.connect("https://parentaccess.ocps.net/Progress/ProgressDetails.aspx").data(target.substring(0,target.length()-5)+"txtClass_DBID",dBID).data("__LASTFOCUS","").data("__EVENTVALIDATION", eventValidation).data("__VIEWSTATE", viewState).cookie("ASP.NET_SessionId", cookie).data("__EVENTTARGET",target).data("DropDownListGradingPeriod","3").data("__EVENTARGUMENT","").header("Content-Type","text/html; charset=utf-8").header("Connection", "keep-alive").header("Cache-Control", "private").get();
请注意我已经尝试了Connection.Response和JSOUP.connect与POST数据,但是一直收到doc2的错误(res将加载页面,但不能传递信息,因为没有生成表格给定的POST数据)。谢谢!
答案 0 :(得分:0)
使用HTMLUNIT处理javascript。
答案 1 :(得分:0)
花了几天后,我发现的唯一解决方案是htmlunit。
以下是工作代码:
HtmlPage page = webClient.getPage("PAGE_URL");
InputStream inputStream =
page.getElementById({EL_ID}").click().getWebResponse().getContentAsStream();
OutputStream outputStream = new FileOutputStream(new File("FILE_NAME"));
IOUtils.copy(inputStream, outputStream);