且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Jsoup(查找元素)

更新时间:2023-12-03 21:31:22

  1. 通过其ID(应该是唯一的)获取父级div:

Elements parent = doc.select("div#mw-body-content");

  • 获取此元素中的所有p标签(包括您想要的第二个标签):

  • Get all p tags in this element (including the second one you would like to have):

    Elements paragraphs = parent.getElementsByTag("p");
    

  • 取第二个:

  • Take the second of it:

    String text = paragraphs.get(1).text();