Don't use index based substring searches. You want to use StringUtils.substringafter(page, "class....") instead.