我试图从 html 中获取一些数据。这是我的代码:
public static void main(String[] args) {
final String str = "<div class=\"b-vacancy-list-salary\">\n" +
" from 50 000\n" +
" to 70 000\n" +
" USD.\n" +
" </div>";
System.out.println(Arrays.toString(getTagValues(str).toArray()));
}
static final String tag = "<div class=\"b-vacancy-list-salary\">\n";
private static final Pattern TAG_REGEX = Pattern.compile(tag+"(.+?)</div>");
private static List<String> getTagValues(final String str) {
System.out.println(tag);
final List<String> tagValues = new ArrayList<String>();
final Matcher matcher = TAG_REGEX.matcher(str);
while (matcher.find()) {
tagValues.add(matcher.group(1));
}
return tagValues;
}
它返回[]
,但不返回值。怎么了?