Home > Net >  How to pass a parameter to a Jsoup connection URL?
How to pass a parameter to a Jsoup connection URL?

Time:12-18

The following html doc has 1629 pages, and I want to get data from all of them:

Document doc = Jsoup.connect("https://nomenclator.anm.ro/medicamente?page=1").get();

I want to pass a parameter to "page" (see the url) as to include it in a loop.

How can I achive thease in Jsoup?

CodePudding user response:

There's no special way to handle URL parameters and the URL is passed as a string. You can simply modify that string in a loop to use loop index as page number:

for (int pageNumber = 1; pageNumber <= 1629; pageNumber  ) {
    Document doc = Jsoup.connect("https://nomenclator.anm.ro/medicamente?page="   pageNumber).get();
    // handle current page here
}
  • Related