0
웹 사이트에 연결하고 URL을 가져 와서 해당 URL에 연결하여 정보를 얻으려고했습니다. 여기 내 코드가있다.자바에서 다른 http 연결을 엽니 다.
URL url = new URL("http://www.nchmf.gov.vn/web/vi-VN/62/23/44/map/Default.aspx");
URLConnection con = url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String l;
String Area;
Pattern Province = Pattern.compile("Thị xã/T.Phố :");
Pattern City = Pattern.compile("<option(.*?)ue=\"(.*?)\">(.*?)</option>");
while ((l=in.readLine())!=null) {
Matcher ProvinceFound = Province.matcher(l);
if (ProvinceFound.find()) {
while((l=in.readLine())!=null
&& !l.contains("</select></span>")){
Matcher CityCode = City.matcher(l);
if(CityCode.find()){
if(!"0".equals(CityCode.group(2))){
URL url1 = new URL("http://www.nchmf.gov.vn/web/vi-VN/62/23/44/map/Default.aspx");
URLConnection con1 = url1.openConnection();
BufferedReader in1 = new BufferedReader(new InputStreamReader(con1.getInputStream()));
while((Area=in1.readLine())!=null){
System.out.println(Area);
break;
}
}
}
}
}
}
}
내가 얻은 결과는 빈 줄뿐입니다. "System.out.println (l);"을 입력하면 여전히 인쇄됩니다. 첫 번째 연결에서 문제가 두 번째 연결이라고 생각합니다.
누구든지 내 코드에서 잘못되었다고 말할 수 있습니까, 정말 고마워요.
표준 Java 명명 규칙을 따르십시오. 변수 (Province, City, ProvinceFound ...)는 대문자로 시작하면 안됩니다. – camickr
코드가 두 번째 연결에 도달 했습니까? 그것을 디버깅하십시오. – fmodos