如何获得特定部分ID下的所有<span>项目? JSoup

问题描述

我正在尝试获取所有位于“收藏夹”部分ID下的“框架标题”类的项目。 Web爬网非常新,所以我相信它很简单。

HTML

axios
  .get("https://pokeapi.co/api/v2/pokemon/")
  .then((res) => {
    return res.data.results
  })
  .then((results) => {
    return Promise.all(results.map((res) => axios.get(res.url)))
  })
  .then((results) => {
    setPokemon(results.map((res) => res.data))
  })

我想检索“框架标题”部分。这就是电影的标题

这是我尝试过的:

<section id="favourites" class="section">
 <h2 class="section-heading">Favorite films</h2>
    <div>
     <a href="/film/wings-of-desire/" class="frame has-menu" data-original-title="Wings of Desire (1987)"><span class="frame-title">Wings of Desire (1987)</span>

解决方法

尝试一下。

String url = "https://letterboxd.com/saka1029/";
Document doc = Jsoup.connect(url).get();
Elements films = doc.select("section#favourites span.frame-title");
for (Element film : films) {
    System.out.println(film);
}

输出:

<span class="frame-title">Ghost in the Shell</span>

这是我的最爱。 :)