Android Network reader _ jsoup resolution application, android_jsoup
This is a Web reader that uses jsoup to parse Html content. It was completed in college and extracted content through parsing against the Web page Element Design of CSDN. The core function is jsoup resolution. The following are related:
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: The ITBlog acquisition tool that uses URL-based html parsing to obtain information about network articles. It mainly uses the html parsing tool Jsoup ** @ author moho **/public class I TBlogUtil {/*** get article List ** @ param url * requested URL * @ return List <ITBlog> IT read Article List **/public static List <ITBlog> getITBlogList (string url) {List <ITBlog> itBlogs = new ArrayList <ITBlog> (); try {Document doc = Jsoup. connect (url ). get (); Elements titles = doc. getElementsByClass (Constant. ITBLOG_TITLE_CLASS ). tagName ("a"); // obtain all the label Elements of class = link_title, Elements dates = doc. getElementsByClass (Constant. ITBlOG_DAT E_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); ITBlog itBlog = new ITBlog (); if (iconUrl! = Null) itBlog. setIconUrl (iconUrl); // you can specify the URL icon for each article. setTilte (titles. get (I ). text (); // obtain the text in tag a, that is, the article title itBlog. setDate (dates. get (I ). text (); // get the posting date of the article itBlog. setUrl (blogUrl); // obtain the href value of the hyperlink attribute itBlogs. add (itBlog) ;}} catch (Exception e) {e. printStackTrace ();} return itBlogs ;} /*** get article content ** @ param url * request 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;}/*** get the article icon, parse the img Tag Based on the URL of the article to obtain the src attribute value ** @ param blogUrl * the requested Article URL * @ return String IT read Article icon URL **/public static String getIconUrlByBlogUrl (String blogUrl) {String iconUrl = null; try {Document doc = Jsoup. connect (blogUrl ). get (); Element contentElement = doc. getElementById (Constant. ITBlOG_CONTENT_ID); // obtain the content area Elements imgElements = contentElement. getElementsByTag ("img"); if (imgElements. size ()> 0) iconUrl = imgElements. get (0 ). attributes (). get ("src"); // obtain UIRL. By default, the first img URL is obtained.} catch (Exception e) {e. printStackTrace ();} return iconUrl ;}}
: Http://tcl.anzhi.com/soft_450735.html http://www.nduoa.com/apk/detail/444229
Code downloading: CSDN is a breeze and cannot be passed. Try again later in the evening.