【发布时间】:2016-09-04 22:23:21
【问题描述】:
我需要从 html 标签中提取文本。我写了一个代码,但没有提取文本。下面是我的代码
import java.util.regex.Matcher;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.regex.Pattern;
class getFontTagText{
String result = null;
public static void main(String args[]){
try{
getFontTagText text = new getFontTagText();
BufferedReader r = new BufferedReader(new FileReader("target.html"));
Pattern p = Pattern.compile("<FONT FACE=\"Arial\" SIZE=\"1\" COLOR=\"\\W|_000000\" LETTERSPACING=\"0\" KERNING=\"0\">(//AZUZZU Full Service Provision)</FONT>",Pattern.MULTILINE);
String line;
System.out.println("Came here");
while((line = r.readLine()) != null){
Matcher mat = p.matcher(line);
while(mat.find()){
System.out.println("Came here");
String st = mat.group(1);
System.out.format("'%s'\n", st);
}
}
}catch (Exception e){
System.out.println(e);
}
}
}
html文件在这里
<P ALIGN="LEFT">
<FONT FACE="Arial" SIZE="1" COLOR="#000000" LETTERSPACING="0" KERNING="0">ZUZZU Full Service Provision</FONT>
</P>
<P ALIGN="LEFT">
<FONT FACE="Arial" SIZE="1" COLOR="#000000" LETTERSPACING="0" KERNING="0">ü ö ä Ä Ü Ö ß</FONT>
</P>
mat.group(1) 被打印为“null”而不是文本。非常感谢任何帮助。
【问题讨论】: