Jsoup没有显示在网页上可见的某些元素

问题描述

我们可以在此页面https://www.futbin.com/21/player/541/lionel-messi上看到, 有ps-lowest-1 span元素,当我通过

doc.getElementById("ps-lowest-1")并不能给我带来数据价格的吸引力,而且文本也会破折号,这可能是导致此问题的原因。

解决方法

您需要做的就是浏览Chrome开发者工具中的网络http请求/响应。

如果找到所需的值(Ps4为688000,则可以查看请求/响应,最终在以下请求中找到该值:

https://www.futbin.com/21/playerPrices?player=158023&rids=50489671&_=1603238284786

这是我认为您想要的数据。

要解析它,您可以使用:

String url = "https://www.futbin.com/21/playerPrices?player=158023&rids=50489671&_=1603238284786";
ResponseEntity<String> document = restTemplate.getForEntity(url,String.class);
String json = document.getBody();
List<String> listOfItems = JsonPath.read(json,"$.path[*].to.items.you.want");

这应该使您大致了解如何获取所需的数据。