Search code examples
javajsoupkeywordkeyword-search

Is there a way to search for more than one keyword in a search bar in JSoup?


Java Code for one keyword-search

Document doc = Jsoup.connect("https://www.medhelp.org/search")
                .data("query", "diabetes")
                .get();

Is there a way to map more than one keyword e.g diabetes or/and acne, in the search bar?


Solution

  • You don't have to do anything special. Just type your query directly with a space:

    Document doc = Jsoup.connect("https://www.medhelp.org/search")
                   .data("query", "diabetes acne")
                   .get();
    

    Alternatively, instead of passing data you could just take a look how the browser transforms entered input into URL parameters:

    enter image description here

    and you can just GET this URL without sending data, so it will be enough to do:

    Document doc = Jsoup.connect("https://www.medhelp.org/search?utf8=✓&query=diabetes+acne")
                   .get();