0

I am trying to parse data from a site based on the user's input but the site uses dynamic urls (URLs that contain "?") and so once the user inputs a number and submits, the url changes. The issue with this is that my app connects to the initial url where the user inputs the data but once the user clicks "submit" and the url changes, the next time I try to retrieve the data it give me null since the url is different. Is there a way to work around this issue using Jsoup on android?

Manu
  • 1
  • 2

1 Answers1

1

You can get current URL by using url() method from Connection.Response class. You can get this instance by using execute() on created Connection.

So your code can look more or less like

String loginPage = "http://www.domain.com/login.php";
Connection.Response response = Jsoup
        .connect(loginPage)
        .data("username", "XXX", "password", "YYY")
        .followRedirects(true)
        .method(Method.POST)
        .execute();     

String url = response.url().toString();//<-- here you should get new url
Map<String, String> loginCookies = response.cookies();

Document doc = Jsoup.connect(url)
          .cookies(loginCookies)
          .get();
Pshemo
  • 122,468
  • 25
  • 185
  • 269