Search in sources :

Example 1 with VkException

use of me.ruslanys.vkmusic.exception.VkException in project selenium_java by sergueik.

the class ScraperVkClient method fetchUserId.

@Override
@SneakyThrows
public Long fetchUserId() {
    Connection.Response response = Jsoup.connect(PATH_BASE).userAgent(USER_AGENT).cookies(cookies).method(Connection.Method.GET).execute();
    Matcher matcher = Pattern.compile("id: (\\d+)").matcher(response.body());
    if (!matcher.find() || "0".equals(matcher.group(1).trim())) {
        throw new VkException("Не удалось получить ID пользователя.");
    }
    Long id = Long.valueOf(matcher.group(1));
    log.info("User ID: {}", id);
    return id;
}
Also used : VkException(me.ruslanys.vkmusic.exception.VkException) Matcher(java.util.regex.Matcher) Connection(org.jsoup.Connection) SneakyThrows(lombok.SneakyThrows)

Aggregations

Matcher (java.util.regex.Matcher)1 SneakyThrows (lombok.SneakyThrows)1 VkException (me.ruslanys.vkmusic.exception.VkException)1 Connection (org.jsoup.Connection)1