下面这段程序检测读入网页所使用的货币符号,如果直接比较给出货币符号,在本地运行可以通过,但是部署到服务器上,特殊的货币符号将是服务器返回错误信息,比如英镑符号或欧元符号,所以这里用unicode编码来解决这个问题,如 \u00A3z而不用英镑符号£
url = new URL(
"http://www.bonhams.com/cgi-bin/public.sh/pubweb/publicSite.r?sContinent=EUR&screen=Catalogue&iSaleNo=18897&maxrows=1000");
BufferedReader in = new BufferedReader(new InputStreamReader(
url.openStream(), "ISO-8859-1"));
String str;
try {
while ((str = in.readLine()) != null) {
if (str.toLowerCase().contains("estimate: ")||str.toLowerCase().matches("(.+)sold(.+)for(.+)\\d(.*)")){
String tempStr = str.replaceAll(
"(<[/]?([a-zA-Z0-9 -=\"'&\\?\\._/:])+[/]?>)",
"").trim();
tempStr = new String(tempStr.getBytes(chset),Charset.forName("ISO-8859-1") );
if (tempStr.contains("\u00A3")){ // £
System.out.println("British Pound");
System.out.println("\u00A3");
} else if (tempStr.contains("$") || tempStr.contains("USD")) {
System.out.println("US Dollar");
System.out.println("$");
} else if (tempStr.contains("H")) {
System.out.println("Honk Kong Dollar");
System.out.println("HK$");
} else if (tempStr.contains("\u20AC")||tempStr.contains("EUR")) {
System.out.println("Euro");
System.out.println("\u20AC"); // €
} else if (tempStr.contains("C")) {
System.out.println("Zurich Franc");
System.out.println("CHF");
}
}
}
in.close();
} catch (Exception e) {
e.printStackTrace();
}