我正在尝试从网页中检索数据,示例 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>
要选择 ul 使用这个:
Document doc = Jsoup.parse(input, "UTF-8", "http://example.com/");
Elements ul = doc.select("ul"); // select ul
请参阅此处的文档:Jsoup 文档
例子 :
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());
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句