How to obtain the Administrative region of National Bureau of Statistics by using java
In this issue, the editor will bring you about how to use java to obtain the administrative region of the National Bureau of Statistics. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
1. The program can take the required provinces, cities, counties, townships (streets) and village (neighborhood) committees according to the needs, and the code is 12 digits.
2. The acquired year can be changed.
3. It can be written into the database according to the requirements, easy to use, and can be updated and maintained once a year.
4. The National Bureau of Statistics has access restrictions, so it is not suitable to obtain all the data of the whole country at once. It is suggested that it can be divided into provinces and obtained by stages.
The implementation code is as follows:
Import java.io.BufferedReader
Import java.io.InputStreamReader
Import java.net.CookieHandler
Import java.net.CookieManager
Import java.net.CookiePolicy
Import java.net.HttpURLConnection
Import java.net.URL
Import java.nio.charset.Charset
Import java.util.List
/ * *
Obtaining administrative divisions from the National Bureau of Statistics
National Bureau of Statistics-NBOS (National Bureau of Statistics)
, /
/ * param args * @ throws Exception * / public static void main (String [] args) throws Exception {String url = baseUrl + "index.html"; / / if you need to set the agent / / initProxy ("xx.xx.xx.xx", "xx"); String str = getContent (url). ToUpperCase () String [] arrs = str.split (") + 2, s.indexOf ("); if (! ") Beijing ".equals (name)) {continue;} System.out.println (" acquisition province: "+ name); readShi (aForce name) * @ param list * @ throws Exception * / public static void readShi (String url,String name) throws Exception {String content = getContent (baseUrl+url) .toUpperCase (); String [] citys = content.split ("CITYTR"); / /'> 110100000000 municipal district ") + 2, strs[ si] .indexOf (")) System.out.println ("cityCode:" + cityCode);} else {cityName = name+ strs[ si] .substring (strs[ si] .indexOf ("" > ") + 2, strs[ si] .indexOf (")); System.out.println (" get the city: "+ cityName) }} readXian (cityUrl.substring (0, cityUrl.indexOf ("/") + 1), cityUrl,cityName);}} / * * read county data * @ param url * @ throws Exception * / public static void readXian (String prix,String url,String cityName) throws Exception {String content = getContent (baseUrl+url). ToUpperCase () String [] citys = content.split ("COUNTYTR"); for (int iTunes 1; I