Skip to content

Instantly share code, notes, and snippets.

@ermakovpetr
Created July 27, 2015 15:24
Show Gist options
  • Save ermakovpetr/3edb3f050729de0157a8 to your computer and use it in GitHub Desktop.
Save ermakovpetr/3edb3f050729de0157a8 to your computer and use it in GitHub Desktop.
String userId = id.next();
if (response.getStatusCode() == 302 || response.getStatusCode() == 404) {
continue;
}
String responseBody = response.getResponseBody();
Document docVKProfilePage = Jsoup.parse(responseBody);
if (docVKProfilePage.select("div[class=profile_info_cont bl_item]").isEmpty()) {
String serviceMsg = docVKProfilePage.select("div.service_msg").first().text();
if (!"Страница удалена либо ещё не создана.".equals(serviceMsg)) {
LOGGER.error("Error response from vk http, user: " + userId + " data: " + responseBody);
Thread.sleep(20000);
throw new RuntimeException("Banned while processing job: " + serviceMsg);
}
} else {
AdditionalVKInfo additionalVKInfo = AdditionalVKInfo.parse(userId, docVKProfilePage);
if (additionalVKInfo != null) {
results.add(MAPPER.writeValueAsString(additionalVKInfo));
}
}
----------
String userId = id.next();
if (response.getStatusCode() == 302 || response.getStatusCode() == 404) {
continue;
}
String responseBody = response.getResponseBody();
Document docVKProfilePage = Jsoup.parse(responseBody);
Elements serviceMsgElements = docVKProfilePage.select("div.service_msg");
if (!serviceMsgElements.isEmpty()) { // ТЕПЕРЬ НАДО ПРОВЕРЯТЬ НЕ ПУСТОЙ ЛИ ЭЛЕМЕНТ
String serviceMsg = serviceMsgElements.first().text(); // И ТОЛЬКО В ЭТОМ СЛУЧАЕ СОЗДАВАТЬ ПЕРЕМЕННУЮ
if ("Страница удалена либо ещё не создана.".equals(serviceMsg)) {
continue;
} else {
LOGGER.error("Error response from vk http, user: " + userId + " data: " + responseBody);
Thread.sleep(20000);
throw new RuntimeException("Banned while processing job: " + serviceMsg);
}
}
if (!docVKProfilePage.select("div[class=profile_info_cont bl_item]").isEmpty()) {
AdditionalVKInfo additionalVKInfo = AdditionalVKInfo.parse(userId, docVKProfilePage);
if (additionalVKInfo != null) {
results.add(MAPPER.writeValueAsString(additionalVKInfo));
}
} else {
LOGGER.error("Unexpected behavior. Data: " + responseBody);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment