300,000 개의 URL을 크롤링하려고합니다. 그러나 URL 중간에서 응답 코드를 검색하려고하면 코드가 중단됩니다. 나는 연결이 성립 되었기 때문에 무엇이 잘못 될지 모르지만 그 후에 문제가 발생하고있다. 나는 코드를 읽기 타임 아웃을 설정하고 제안 된대로 요청 속성을 수정했다. 그러나 이제는 코드가 응답 코드를 얻을 수 없다! 모든 제안/포인터를 크게 주시면 감사하겠습니다. 또한 특정 기간 동안 웹 사이트를 핑 (ping) 할 수있는 방법이 있습니까? 그리고 응답이 없으면 다음 웹 사이트로 진행하십시오.응답 코드를 가져올 수 없습니다! 포인터?
URL url=null;
try
{
Thread.sleep(8000);
}
catch (InterruptedException e1)
{
e1.printStackTrace();
}
try
{
//urlToBeCrawled comes from the database
url=new URL(urlToBeCrawled);
}
catch (MalformedURLException e)
{
e.printStackTrace();
//The code is in a loop,so the use of continue.I apologize for putting code in the catch block.
continue;
}
HttpURLConnection huc=null;
try
{
huc = (HttpURLConnection)url.openConnection();
}
catch (IOException e)
{
e.printStackTrace();
}
try
{
//Added the request property
huc.addRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
huc.setRequestMethod("HEAD");
}
catch (ProtocolException e)
{
e.printStackTrace();
}
huc.setConnectTimeout(1000);
try
{
huc.connect();
}
catch (IOException e)
{
e.printStackTrace();
continue;
}
int responseCode=0;
try
{
//Sets the read timeout
huc.setReadTimeout(15000);
//Code hangs here for some URL which is random in each run
responseCode = huc.getResponseCode();
}
catch (IOException e)
{
huc.disconnect();
e.printStackTrace();
continue;
}
if (responseCode!=200)
{
huc.disconnect();
continue;
}
답장을 보내 주셔서 감사합니다. 나는 그것들을 들여다 볼 것이다. – collegian