[size=large][color=green]问题代码在红色部分
问题:执行代码报错:
Exception in thread "main" java.lang.IllegalStateException: No match found ???[/color][/size]
public String getUrlStr(String urlPathStr){
String setStr = "";
StringBuffer sb = new StringBuffer();
try {
URL readsource = new URL(urlPathStr);
BufferedReader in = new BufferedReader(new InputStreamReader(readsource.openStream(),"utf-8"));
while ((setStr = in.readLine()) != null) {
sb.append(setStr+"\r\n");
}
in.close();
} catch (MalformedURLException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
return sb.toString();//返指定Url的抓取的内容
}
[color=red]public static String getByFlagStr(String isStr){
Pattern p = Pattern.compile("<a.*?天气.*?℃.*?</a>");
Matcher m = p.matcher(isStr);
m.matches();
if(m.find()){//启动开始匹配
m.group();
}
return m.group();
}[/color]
public static void main(String[] args) {
System.out.println(new GetUrlStr().getByFlagStr(new GetUrlStr().getUrlStr("http://3g.sina.com.cn/?vt=3&pos=103")));
}