Android Web reader _jsoup analytic application

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.