Implement the RESTful endpoint API, which simultaneously makes calls to the following websites: https://pizzerijalimbo.si/meni/ https://pizzerijalimbo.si/kontakt/ https://pizzerijalimbo.si/my-account/ https://pizzerijalimbo.si/o-nas/ The input for the endpoint is ‘integer’, which represents the number of simultaneous calls to the above web pages (min 1 represents all consecutive calls, max 4 represents all simultaneous calls). Extracts a short title text from each page and saves this text in a common global structure (array, folder (). The program should also count successful calls. Finally, the service should list the number of successful calls, the number of failed calls and the saved address texts from all web pages.
import java.util.Arrays; import java.util.List; import java.io.IOException; import java.net.URL; import java.util.Scanner; @RestController public class APIcontroller { @Autowired private RestTemplate restTemplate; List<String> websites = Arrays.asList("https://pizzerijalimbo.si/meni/", "https://pizzerijalimbo.si/kontakt/", "https://pizzerijalimbo.si/my-account/", "https://pizzerijalimbo.si/o-nas/"); @GetMapping("/podatki") public List<Object> getData(@RequestParam(required = true) int numberOfWebsites) { List<String> websitesToScrape = websites.subList(0, numberOfWebsites); for (String website : websitesToScrape) { Document doc = Jsoup.connect("https://pizzerijalimbo.si/meni/").get(); log(doc.title()); Elements newsHeadlines = doc.select("#mp-itn b a"); for (Element headline : newsHeadlines) { log("%s\n\t%s", headline.attr("title"), headline.absUrl("href")); } } } }
log
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)