private List < Element > extractElements ( String content , String selector , int amount ) { Element body = parseContent ( content ) ; List < Element > elements = body . select ( selector ) ; if ( elements . size ( ) > 0 ) { elements = filterParents ( elements ) ; if ( amount >= 0 ) { // limit to the indicated amount elements = elements . subList ( 0 , Math . min ( amount , elements . size ( ) ) ) ; } // remove all from their parents for ( Element element : elements ) { element . remove ( ) ; } } List < Element > results = new ArrayList < Element > ( ) ; // first element is the body results . add ( body ) ; results . addAll ( elements ) ; return results ; }
Extracts elements from the HTML content .