This is a Jsoup parsing HTML to obtain content of the network reader, the university period of leisure completed, Control CSDN Web page element design to extract content, the core function is to use jsoup parsing. The following are relevant:
Core parsing code:
Package Com.weiyi.itreader.util;import Java.util.arraylist;import Java.util.list;import org.jsoup.Jsoup;import Org.jsoup.nodes.document;import Org.jsoup.nodes.element;import Org.jsoup.select.elements;import Android.util.Log; Import Com.weiyi.itreader.common.constant;import com.weiyi.itreader.entity.itblog;/** * Function: ITBlog get tool, Through the URL parsing HTML to obtain the information of the network article, mainly used in the HTML parsing tool jsoup * * @author Moho * */public class Itblogutil {/** * get the article List * * @param URL * Requested URL * @return list<itblog> it reading article list * */public static list<itblog> getitbloglist (String url) {LIST&L t;itblog> itblogs = new arraylist<itblog> (); try {Document doc = jsoup.connect (URL). get (); Elements titles = Doc.getelementsbyclass (Constant.itblog_title_class). TagName ("a");//Get All CLASS=LINK_ The label element of title Elements dates = Doc.getelementsbyclass (constant.itblog_date_class); Elements urls = titles.select (constant.href_select); for (int i = 0; i < titles.size (); ++i) {String Blogurl = Constant. itblog_url+ Urls.get (i). AttribuTES (). Get ("href");//URLString ICONURL = Geticonurlbyblogurl (blogurl) for each article; Itblog itblog = new Itblog (); if (iconUrl! = Nu ll) Itblog.seticonurl (ICONURL);//Set the header icon for each article Urlitblog.settilte (Titles.get (i). text ());//Get the text within the a tag, That is, the article title itblog.setdate (Dates.get (i). text ());//Gets the article publication date itblog.seturl (blogurl);//Gets the value of the Hyperlink property href Itblogs.add (Itblog);}} catch (Exception e) {e.printstacktrace ();} return itblogs;} /** * Get article content * * @param URL * Requested URL * @return String it read article content * */public static string Getcontentbyurl (string URL) {String content = ""; try {Document doc = jsoup.connect (URL). get (); Element contentelement = Doc.getelementbyid (constant.itblog_content_id); CONTENT = contentelement.html ();} catch (Exception e) {e.printstacktrace (); return content;} return content;} /** * Get the article icon, according to the article URL Address resolution IMG tag get SRC attribute value * * @param blogurl * Requested article URL * @return String it reading article icon URL * */public s Tatic string Geticonurlbyblogurl (String blogurl) {string iconUrl = null;try {Document doc = Jsoup.connect (blogurl).Get (); Element contentelement = Doc.getelementbyid (constant.itblog_content_id);//Get content area elements Imgelements = Contentelement.getelementsbytag ("img"), if (Imgelements.size () >0) IconUrl = Imgelements.get (0). attributes (). Get ( "src");//Gets Uirl, defaults to the URL of the first encountered IMG} catch (Exception e) {e.printstacktrace ();} return ICONURL;}}
: http://tcl.anzhi.com/soft_450735.html http://www.nduoa.com/apk/detail/444229
Code Download: Csdn convulsions, can't pass, try again at night
Android Web reader _jsoup analytic application