I am trying to submit a form with jsoup and then get the html from the directed page:

import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

public class RF {    

  public static void main(String[] args) throws Exception {

       Connection.Response submitForm =    Jsoup.connect("http://rfinder.asalink.net/free/")
        .method(Connection.Method.POST)
        .execute();

       Document data = Jsoup.connect("http://rfinder.asalink.net/free/autoroute_rtx.php")
        .data("cookieexists", "false")
        .data("id1", "LMML")
        .data("id2", "LIRA")
        .data("submit", "Find Route")
        .cookies(submitForm.cookies())
        .post();
       System.out.println(data);

   }

}

I think the problem may be that the submit button does not have a name tag and I don't know what to include instead of the 'submit' part.

What can I do please?

有帮助吗?

解决方案

using jsoup to submit is not that easy, basically the motive of jsoup is to parse the html document for you, for submission of forms, and all other things that involve postback or getting results dynamically, i suggest you should use the Selenium, here is the basic tutorial to get you started

https://code.google.com/p/selenium/wiki/GettingStarted

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top