Using Jsoup to analyze weather forecast

Source: Internet
Author: User

Java an open source parsing HTML program Jsoup HTML parsing, and let us like the CSS operation to get the parsed content, this article uses its characteristics to parse

Jsoup Open source jar package please download it yourself

public class weatherinfo {    /**     * @ Param args     */    public static void main ( String[] args)  {        getcityweatherinfo ();         //getcityandurl ();     }    /**      * jsoup.connect example      *  get Weather Forecast web page, and analyze the weather phenomenon    Air    wind    wind      */    public  Static void getcityweatherinfo () {        document doc;                 String  str2 =  "Http://www.weather.com.cn/html/weather/101190101.shtml";         try {&nbsP;           doc = jsoup.connect (STR2). get ();             Elements content =  Doc.getelementsbyclass ("yubaotable");              for  (element link : content)  {               string linktext = link.text ();               string[] strs = linktext.split ("   ");              for  (String  s : strs) {                   system.out.print (s+ "\ T");               }&Nbsp;             system.out.println ();             }         } catch  (ioexception e)  {             e.printstacktrace ();        }     }    /**     *  get the cities in each province and their corresponding connections       */    public static void getcityandurl () {         Document doc;        String  str2 =  "Http://www.weather.com.cn/guangdong/index.shtml";         try {            doc =  Jsoup.connect (STR2). Get ();            Element content =  Doc.getelementbyid ("Forecastid");                         Elements es =  Content.children ();             for ( Element  e : es ) {                 node node = e.childnode (0). Childnode (0);                                  system.out.print (Node.childnode (0) +  "\ T");                 system.out.println ( Node.attr ("href"));             }                    } catch  (ioexception e)  {             e.printstacktrace ();         }    }}

Jsoup Chinese Development Manual: http://www.open-open.com/jsoup/

Jsoup Home: http://jsoup.org/

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.