Jsoup parsing and traversing an HTML document (ii)

Source: Internet
Author: User

About the font adjustments in the Eclipse Editor Rollup console:

1. Download the Jsoup jar package: Http://jsoup.org/download

2, Jsoup Development Handbook for English: http://jsoup.org/cookbook/

3,jsoup Jsoup Cookbook Chinese version: http://www.open-open.com/jsoup/

-                     - -                     - -                &N Bsp    - -                     - -    and nbsp                - -                &N Bsp    - -               -            & nbsp        - 

-                      - -                      - -                      - -                      - - - -                      - -                -                      -

Small instance:

1  Packagecn.cast.test;2 3 4 5 ImportOrg.jsoup.Jsoup;6 Importorg.jsoup.nodes.Document;7 Importorg.jsoup.nodes.Element;8 Importorg.jsoup.select.Elements;9 Ten  One Importjava.io.IOException; A  - ImportOrg.jsoup.Jsoup; - ImportOrg.jsoup.Jsoup; the Importorg.jsoup.nodes.Document; - Importorg.jsoup.nodes.Element; - Importorg.jsoup.select.Elements; -  +  -  Public classtest_1 { +  A      Public Static voidMain (string[] args) { at         //TODO auto-generated Method Stub - geturlandtitle (); - gettextmes (); -     } -      -      Public Static voidGeturlandtitle () in     { -String url= "http://finance.sina.com.cn/"; to         Try { +Document doc=jsoup.connect (URL). Timeout (10000). get ();//get all infomation from URL website -             //System.out.println (DOC);  theElements Listdiv = Doc.getelementsbyattributevalue ("Class", "fin_tabs0_c0"); *             //System.out.println (listdiv); $              for(Element div:listdiv) {Panax NotoginsengElements links = Div.getelementsbytag ("a"); -                 //System.out.println (links); the                   for(Element link:links) { +String linkhref = link.attr ("href"). Trim (); AString LinkText =link.text (). Trim (); theSystem.out.println (linkhref+ "\ T" +linkText); +                  }     -              } $}Catch(IOException e) { $             //TODO auto-generated Catch block - e.printstacktrace (); -         } the     } -     Wuyi      Public Static voidgettextmes () the     { -String url= "http://finance.sina.com.cn/hy/20140823/100220099682.shtml"; WuString textmes= ""; -         Try { AboutDocument doc=jsoup.connect (URL). Timeout (10000). get (); $Elements Listdiv = Doc.getelementsbyattributevalue ("Class", "Blkcontainersblkcon Bshare_pop"); -             //System.out.println (listdiv); -              for(Element div:listdiv) -             { AElements Textinfos=div.getelementsbytag ("P"); +                 //System.out.println (Textinfos); the                  for(Element Textinfo:textinfos) -                 { $String text=textinfo.text (). Trim (); theTextmes=textmes+text+ "\ n"; the                 } the             } the System.out.println (textmes); -}Catch(IOException e) { in             //TODO auto-generated Catch block the e.printstacktrace (); the         } About     } the}
test_1

Jsoup parsing and traversing an HTML document (ii)

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.