我正在尝试从网页中检索数据,下面显示了示例html代码,我想检索数据并将其显示在列表视图中。
<html>
<head>
<title>Index of /abc/xyz/Female/pqr</title>
</head>
<body>
<h1>Index of /abc/xyz/Female/pqr</h1>
<ul>
<li><a href="//abc/xyz/Female/pqr"> Parent Directory</a></li>
<li><a href="2016060500004.png"> 2016060500004.png</a></li>
<li><a href="2016060500011.png"> 2016060500011.png</a></li>
<li><a href="2016060500012.png"> 2016060500012.png</a></li>
</ul>
</body>
</html>
答案 0 :(得分:1)
要选择ul,请使用
Document doc = Jsoup.parse(input, "UTF-8", "http://example.com/");
Elements ul = doc.select("ul"); // select ul
在此处参考文档:Jsoup docs
示例:
String html = "<html>"+
"<head>"+
"<title>Index of /abc/xyz/Female/pqr</title>"+
"</head>"+
"<body>"+
"<h1>Index of /abc/xyz/Female/pqr</h1>"+
"<ul>" +
"<li><a href=\"//abc/xyz/Female/pqr\"> Parent Directory</a></li>"+
"<li><a href=\"2016060500004.png\"> 2016060500004.png</a></li>"+
"<li><a href=\"2016060500011.png\"> 2016060500011.png</a></li>"+
"<li><a href=\"2016060500012.png\"> 2016060500012.png</a></li>"+
"</ul>" +
"</body>"+
"</html>";
Document doc = Jsoup.parse(html);
Elements links = doc.select("ul"); // select ul
for(Element b : links){
System.out.println(b.text());
}