0

我试图从 .aspx 页面中检索一些数据。我想要做的是告诉服务器我想从页面的下拉菜单中获得某个值。如果我没有错,您可以通过更改此值来做到这一点:“ctl00$holder$ddlEntry”。当您是普通用户时,您想点击刷新按钮。由于jsoup中没有实现javascript,我试图通过发出与刷新按钮相同的发布请求来获取数据。我究竟做错了什么?

编辑:我的问题是:我的页面没有更新,我仍然得到相同的页面。

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());

}
4

1 回答 1

0

在这种情况下,您可以使用 Selenium Libary for Java。它模拟特定的浏览器并可以点击按钮等。

于 2013-11-14T09:20:50.220 回答