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/