如何在没有第一类的情况下获取所有图像:content.slide0。
在我的示例中,我使用 Jsoup 库,它在 WebView 中显示可选择的元素。
元素 element = doc.select("HERE_SOLUTION");
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>TESTING TITLE</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="css/normalize.min.css">
<link rel="stylesheet" href="css/main.css?4231">
<script src="js/vendor/modernizr-2.6.2.min.js"></script>
<style type="text/css" media="screen">
body {
background: #fe9600 url('images/1389219790_bg2.jpg') no-repeat fixed top center;
}
#content.slide0 {
background: url('img/1234.jpg') no-repeat scroll top left;
width: 970px;
height: 474px;
margin: 0 auto;
}
#content.slide1 {
background: url('images/1235.jpg') no-repeat scroll top left;
width: 970px;
height: 474px;
margin: 0 auto;
}
#content.slide2 {
background: url('images/1236.jpg') no-repeat scroll top left;
width: 970px;
height: 474px;
margin: 0 auto;
}
最佳答案
Jsoup 解析 HTML 但不解析 CSS。由于您试图从 CSS 获取图像,因此您不能使用 Jsoup 选择器。您可能应该使用正则表达式。
在你的 '.*'
正则表达式中应该提取
1. 'img/1234.jpg'
2. '图片/1235.jpg'
3. '图片/1236.jpg'
4. '图片/1389219790_bg2.jpg'
最后一个可能不需要。您可以删除这可能检查字符串的长度。
或者,您可以使用 CSS 解析器,如 this .
希望这对您有所帮助!
关于android - Jsoup 从 CSS 中选择元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21069823/