我试图从.aspx页面中检索一些数据。我想要做的是告诉服务器我想从页面的下拉菜单中获得某个值。如果我没有错,你可以通过改变这个值来做到这一点:“ctl00 $ holder $ ddlEntry”。当您是普通用户时,您想要点击刷新按钮。由于javascript没有在jsoup中实现,我试图通过发送与刷新按钮相同的发布请求来获取数据。我做错了什么?
编辑:我的问题是:我的页面没有更新,我仍然得到同一页面。
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
String url = "http://extranet.net4gas.cz/capacity_ee_point.aspx";
Document doc = Jsoup.connect(url).get();
Elements viewState = doc.select("input[name=__VIEWSTATE");
Elements eventValidation = doc.select("input[name=__EVENTVALIDATION]");
Map<String,String> allFields = new HashMap<String,String>();
allFields.put("ctl00$holder$ScriptManager1", "ctl00$holder$UpPanel");
allFields.put("ctl00$holder$break", "rbTypC1");
allFields.put("ctl00$holder$enex", "rbTypB1");
allFields.put("ctl00$holder$ddlEntry", "4"); //resembles value in dropdown menu
allFields.put("ctl00$holder$ddlMonth1", "11");
allFields.put("ctl00$holder$ddlYear1", "2013");
allFields.put("ctl00$holder$ddlMonth2", "12");
allFields.put("ctl00$holder$ddlYear2", "2018");
allFields.put("__EVENTTARGET", "");
allFields.put("__EVENTARGUMENT", "");
allFields.put("__LASTFOCUS", "");
allFields.put("__VIEWSTATE", viewState.val());
allFields.put("__EVENTVALIDATION", eventValidation.val());
allFields.put("__ASYNCPOST", "true");
allFields.put("ctl00$holder$bRefresh", " Refresh ");
System.out.println(allFields);
Connection.Response res = Jsoup.connect(url)
.data(allFields)
.userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0")
.timeout(5*1000)
.method(Method.POST).
execute();
Document doc2 = Jsoup.connect(url)
.cookies(res.cookies())
.timeout(5*1000)
.get();
System.out.println(doc2.html());
}
答案 0 :(得分:0)
在这种情况下,您可以使用Selenium Library for Java。它模拟特定的浏览器,可以点击按钮等。