Some of the things that have recently been found to be boring are crawling data on a Web page, then displaying it using the native code of Android, or borrowing Web data to display it in a custom view.
Get and parse data with the Jsoup-1.10.2.jar library. (Jsoup Baidu Cloud: Http://pan.baidu.com/s/1nvSFKyl)
Jsoup Official documents:
https://jsoup.org/cookbook/
Chinese documents:
http://www.open-open.com/jsoup/
Application Scenarios:
I need to get the data on the Blog Park Web page, the tagged text title, the link, the text introduction.
1, browser open the Web page, and then right-click to view the source page, or press F12 review elements. (difference: the review element (or use the Developer tool, Firebug) to see is now real-time content (after JS modification), and the Web source code see is the first browser received HTTP response content)
Find the corresponding HTML code.
2, find the corresponding node <div class= "Post_item_body" > <a class= "Titlelnk" > <p class= "Post_item_summary"; Use Jsoup parsing. The code is as follows:
Public voidTestjsoup () {NewThread (NewRunnable () {@Override Public voidrun () {//TODO auto-generated Method Stub Try{Document doc= Jsoup.connect ("http://www.cnblogs.com/"). get (); Elements Elements= Doc.select ("Div.post_item_body"); for(Element element:elements) {elements title= Element.select ("A.titlelnk"); LOG.E ("Title:", Title.get (0). text ()); LOG.E ("url", Title.get (0). attr ("href")); Elements content= Element.select ("P.post_item_summary"); LOG.E ("Content:", Content.get (0). text ()); } } Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); } Catch(Exception e) {//Todo:handle Exception}} ). Start (); }
3, print the log, as follows:
Here, the Web page data can be basically parsed out.
Android parsing HTML Web page data the first method Jsoup (i)