使用jsoup在网页上查找元素

Using jsoup to find element on webpage

我正在尝试从以下页面获取字符串格式的船长姓名。在这种情况下,它将是 Kane

http://fantasy.premierleague.com/entry/390/event-history/30/

我正在使用 Jsoup,无论我尝试什么,它都不起作用,只是一个空白字符串。如果有人对如何执行此操作有任何建议,将不胜感激。提前致谢

div.ismPlayerContainer:has(img.ismCaptainOn) span.JS_ISM_NAME

这个 css 选择器将 return 带有船长名字的跨度。

您可以在这里查看:Jsoup

现在它只是return你在运行这个css文档选择器之后将拥有的元素的文本。

希望对您有所帮助!

以上方法有效。非常感谢你。我的代码如下

字符串 url2 = "http://fantasy.premierleague.com/entry/390/event-history/30/"; 文档 document2 = Jsoup.connect(url2).get();

元素元素=document2.select("div.ismPlayerContainer:has(img.ismCaptainOn) span.JS_ISM_NAME"); System.out.println(elements.text());