@@ -77,21 +77,8 @@ private void parsePageData(String page) {
7777 ArrayList <Collection > collections = new ArrayList <>();
7878 try {
7979 Document doc = Jsoup .parse (s , AppConfig .GITHUB_BASE_URL );
80- Elements elements = doc .getElementsByClass (
81- "d-flex border-bottom border-gray-light pb-4 mb-5" );
82- for (Element element : elements ) {
83- Element titleElement = element .select ("div > h2 > a" ).first ();
84- Element descElement = element .select ("div" ).last ();
85- String id = titleElement .attr ("href" );
86- id = id .substring (id .lastIndexOf ("/" ) + 1 );
87- String title = titleElement .textNodes ().get (0 ).toString ();
88-
89- List <TextNode > descTextNodes = descElement .textNodes ();
90- int descIndex = descTextNodes .size () == 0 ? 0 : descTextNodes .size () - 1 ;
91- String desc = descTextNodes .get (descIndex ).toString ().trim ();
92- Collection collection = new Collection (id , title , desc );
93- collections .add (collection );
94- }
80+ collections .addAll (getTopCollections (doc ));
81+ collections .addAll (getBellowCollections (doc ));
9582 } catch (Exception e ) {
9683 e .printStackTrace ();
9784 }
@@ -114,4 +101,46 @@ private void parsePageData(String page) {
114101 });
115102 }
116103
104+ private ArrayList <Collection > getTopCollections (Document doc ){
105+ ArrayList <Collection > collections = new ArrayList <>();
106+ Elements elements = doc .getElementsByClass (
107+ "col-12 col-sm-6 col-md-4 mb-4" );
108+ for (Element element : elements ) {
109+ Element hrefElement = element .select ("a" ).first ();
110+ Element titleElement = element .select ("a > p" ).first ();
111+ Element descElement = element .select ("a > p" ).last ();
112+ String id = hrefElement .attr ("href" );
113+ id = id .substring (id .lastIndexOf ("/" ) + 1 );
114+ String title = titleElement .textNodes ().get (0 ).toString ();
115+ String desc = descElement .textNodes ().get (0 ).toString ();
116+
117+ // List<TextNode> descTextNodes = descElement.textNodes();
118+ // int descIndex = descTextNodes.size() == 0 ? 0 : descTextNodes.size() - 1;
119+ // String desc = descTextNodes.get(descIndex).toString().trim();
120+ Collection collection = new Collection (id , title , desc );
121+ collections .add (collection );
122+ }
123+ return collections ;
124+ }
125+
126+ private ArrayList <Collection > getBellowCollections (Document doc ){
127+ ArrayList <Collection > collections = new ArrayList <>();
128+ Elements elements = doc .getElementsByClass (
129+ "d-flex border-bottom border-gray-light pb-4 mb-5" );
130+ for (Element element : elements ) {
131+ Element titleElement = element .select ("div > h2 > a" ).first ();
132+ Element descElement = element .select ("div" ).last ();
133+ String id = titleElement .attr ("href" );
134+ id = id .substring (id .lastIndexOf ("/" ) + 1 );
135+ String title = titleElement .textNodes ().get (0 ).toString ();
136+
137+ List <TextNode > descTextNodes = descElement .textNodes ();
138+ int descIndex = descTextNodes .size () == 0 ? 0 : descTextNodes .size () - 1 ;
139+ String desc = descTextNodes .get (descIndex ).toString ().trim ();
140+ Collection collection = new Collection (id , title , desc );
141+ collections .add (collection );
142+ }
143+ return collections ;
144+ }
145+
117146}
0 commit comments