简体   繁体   中英

Java jsoup link selecting

I have the following code:

Document doc = Jsoup.connect(mainPage).get();

Elements section = doc.select("#main");
Elements allArtTags = section.select("article");
for (Element artTag : allArtTags ){
    Elements atags = artTag.select("a");
}

As you see first I am selecting the #main and then "article" , finally for each element getting the link with select("a") , my question is can this code be optimized in some way so to display again the same links but in more optimized way(or less code)

can this code be optimized in some way so to display again the same links but in more optimized way(or less code)

Write the code like below:

Document doc = Jsoup.connect(mainPage).get();
for (Element aTag : doc.select("#main article a")){

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM