Retourner au contenu associé (journal : recherche-totoz en JavaScript)
Posté par barmic le 30 novembre 2018 à 14:22. En réponse au journal recherche-totoz en JavaScript. Évalué à 5.
public static void searchTotoz(String query) { HttpClient client = HttpClient.newHttpClient(); HttpRequest request = HttpRequest.newBuilder() .uri(URI.create("https://totoz.eu/search.xml?terms=" + query)) .build(); client.sendAsync(request, HttpResponse.BodyHandlers.ofString()) .thenApply(HttpResponse::body) .thenApply(SmokeTestsApplication::extract) .thenAccept(System.out::println) .join(); } public static Collection<String> extractNames(String body) { try { DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document document = builder.parse(new ByteArrayInputStream(body.getBytes())); XPath xpath = XPathFactory.newInstance().newXPath(); String expression = "/totozes/totoz/name/text()"; XPathNodes nodes = xpath.evaluateExpression(expression, document, XPathNodes.class); return StreamSupport.stream(nodes.spliterator(), false).map(Node::getNodeValue).collect(Collectors.toList()); } catch (Exception e) { throw new RuntimeException(e); } }
Complètement à l'arrache, mais c'était l'occasion d'utiliser le nouveau client http de Java 11. C'est assez verbeux (oui c'est java) et la gestion d'erreur est pourrie.
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
# Java 11
Posté par barmic . En réponse au journal recherche-totoz en JavaScript. Évalué à 5.
Complètement à l'arrache, mais c'était l'occasion d'utiliser le nouveau client http de Java 11. C'est assez verbeux (oui c'est java) et la gestion d'erreur est pourrie.