0

iam trying to retrieve some data from an .aspx page. What i want to do is to tell the server that i want to have a certain value from the dropdown menu from the page. If iam not wrong you can do this by changing this value : "ctl00$holder$ddlEntry". When you are a regular user you want to hit the refresh button. Since javascript is not implemented in jsoup, i was trying to get the data by making the same post request as the refresh button. what am i doing wrong?

edit: what my problem is : my page is not updating , iam still getting the same page.

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

}
maxw
  • 1

1 Answers1

0

in this case you can use the Selenium Libary for Java. It emulates a specific Browser and can hit Buttons and so on.

Micha
  • 1
  • iam trying to avoid librarys such selenium or htmlunit, cause they look like a overkill for what iam doing. Isnt there a workaround in jsoup? – maxw Nov 14 '13 at 09:53