统计用区划和城乡划分代码,在线爬取代码【根据实际情况自行更改】
相关依赖【最好使用Java8进行调试】
官方链接
Maven Gradle 离线JAR包下载
转发请标明文章出处 https://blog.csdn.net/AntsCode/article/details/109817067
GetRegionalism.java
/*
* ProjectName: ########
* PackageName: top.smartprinting
* CompanyName: ########
* Datetime: 2020/11/16 下午12:19
* E-mail: MyEvery7655@gmail.com
*/
package top.smartprinting;
import org.jsoup.HttpStatusException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* Description:<br>
*
* @author AntsCode
*/
public class GetRegionalism {
private static final String ROOT_PATH = "http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2020/";
private GetRegionalism() {
}
public static void main(String[] args) {
System.out.println(getCCTV(Area.TOWNTR, getCCTV(Area.COUNTYTR, getCCTV(Area.CITYTR, getP(), false), false), false)
.size());
}
public static List<RegionalismCode> getPCCTV(Area area, String href) {
if (area.equals(Area.TOWNTR)) {
href = href.substring(3, 5) + File.separator + href;
} else if (area.equals(Area.VILLAGETR)) {
href = href.substring(3, 5) + File.separator + href.substring(5, 7) + File.separator + href;
}
return getRegionalismCodeStream(area, href)