java代码自动下载Spring Boot用户手册
本示例演示Spring Boot 1.5.9.RELEASE版本的用户手册下载
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>com.nihaorz</groupId>
<artifactId>spring-boot-doc-download</artifactId>
<version>1.0-SNAPSHOT</version> <dependencies>
<!-- https://mvnrepository.com/artifact/org.jsoup/jsoup -->
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.11.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
</dependencies> </project>
Application.java
package com.nihaorz; import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements; import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.Charset; /**
* @author Nihaorz
*/
public class Application { private static final Charset CHARSET = Charset.forName("UTF-8"); /**
* doc站点地址
*/
private static final String DOC_URL = "https://docs.spring.io/spring-boot/docs/"; /**
* doc起始页
*/
private static final String HTML_URI = "/reference/html/"; /**
* URL分隔符
*/
private static final String URL_SEPARATOR = "/"; /**
* html页面结束标记
*/
private static final String HTML_END_STR = ".html"; public static void main(String[] args) throws IOException {
String storePath = "D:\\IDEA_WS\\OperationCenter_WS\\spring-boot-doc-download\\src\\main\\doc";
String version = "1.5.9.RELEASE";
generateHtmlDoc(storePath, version);
} /**
* 生成文档
*
* @param storePath
* @param version
*/
private static void generateHtmlDoc(String storePath, String version) throws IOException {
String indexPath = DOC_URL + version + HTML_URI;
String html = IOUtils.toString(new URL(indexPath), CHARSET);
saveHtml(storePath, indexPath, html);
Document document = Jsoup.parse(html);
Elements elements = new Elements();
elements.addAll(document.select("span.chapter>a"));
elements.addAll(document.select("span.part>a"));
elements.addAll(document.select("span.appendix>a"));
String urlPath;
System.out.println("共解析得到" + elements.size() + "个子页面");
for (Element element : elements) {
urlPath = element.attr("href");
if (urlPath != null && !"".equals(urlPath.trim())) {
if (!urlPath.startsWith("http")) {
urlPath = indexPath + urlPath;
}
}
html = IOUtils.toString(new URL(urlPath), CHARSET);
saveHtml(storePath, urlPath, html);
}
} private static void saveHtml(String storePath, String urlPath, String html) throws IOException {
if (!urlPath.contains(".html#")) {
if (!urlPath.endsWith(HTML_END_STR)) {
if (urlPath.endsWith(URL_SEPARATOR)) {
urlPath = urlPath + "index" + HTML_END_STR;
} else {
urlPath = urlPath + URL_SEPARATOR + "index" + HTML_END_STR;
}
}
urlPath = urlPath.substring(DOC_URL.length(), urlPath.length());
String localPath = storePath + File.separator + urlPath.replace(URL_SEPARATOR, File.separator);
File file = new File(localPath);
if (!file.exists()) {
file.getParentFile().mkdirs();
}
file.createNewFile();
FileUtils.write(file, html, CHARSET);
System.out.println("保存" + file.getAbsolutePath() + "成功");
}
} }
运行main函数会在D:\IDEA_WS\OperationCenter_WS\spring-boot-doc-download\src\main\doc\1.5.9.RELEASE\reference\html目录下生成html文件
将以下脚本批量为空字符串
<script>if(window.parent==window){(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create','UA-2728886-23','auto',{'siteSpeedSampleRate':100});ga('send','pageview');}</script>
然后将html文件放到tomcat ROOT应用下访问index.html,使用Fiddler抓包会有如下几个文件404:
highlight.css
manual.css
manual-multipage.css
background.png
important.png
note.png
tip.png
warning.png
email-decode.min.js
他们的真是下载地址如下:
https://docs.spring.io/spring-boot/docs/1.5.9.RELEASE/reference/html/css/highlight.css
https://docs.spring.io/spring-boot/docs/1.5.9.RELEASE/reference/html/css/manual.css
https://docs.spring.io/spring-boot/docs/1.5.9.RELEASE/reference/html/css/manual-multipage.css
https://docs.spring.io/spring-boot/docs/1.5.9.RELEASE/reference/html/images/background.png
https://docs.spring.io/spring-boot/docs/1.5.9.RELEASE/reference/html/images/important.png
https://docs.spring.io/spring-boot/docs/1.5.9.RELEASE/reference/html/images/note.png
https://docs.spring.io/spring-boot/docs/1.5.9.RELEASE/reference/html/images/tip.png
https://docs.spring.io/spring-boot/docs/1.5.9.RELEASE/reference/html/images/warning.png
https://docs.spring.io/cdn-cgi/scripts/d07b1474/cloudflare-static/email-decode.min.js
将上面的文件下载下来依次放到html下的css、images、js目录下
在上面的html文件中全局搜索email-decode.min.js并替换为相对路径,然后一个新鲜离线版用户手册就诞生了,从tomcat中拿出来邮件浏览器打开即可使用,还不带google统计,跟官方在线版本简直一毛一样啊。
下面放大招
java代码自动下载Spring Boot用户手册的更多相关文章
- Java后端框架之Spring Boot详解,文末有Java分布式实战项目视频可取
在 Java 后端框架繁荣的今天,Spring 框架无疑是最最火热,也是必不可少的开源框架,更是稳坐 Java 后端框架的龙头老大. 用过 Spring 框架的都知道 Spring 能流行是因为它的两 ...
- 互联网大厂Java面试题集—Spring boot常见面试题(二)
Spring Boot的核心功能与使用优点? 核心功能: 1)Spring Boot项目为独立运行的spring项目,java -jar xx.jar即可运行. 2)内嵌servlet容器(可以选择内 ...
- 互联网大厂Java面试题集—Spring boot面试题(一)
Spring Boot 需要独立的容器运行吗? 可以不需要,内置了 Tomcat/ Jetty 等容器.通过pom.xml中导入依赖: <!--spring-boot-starter-web:代 ...
- Jenkins自动部署spring boot
Jenkins自动部署spring boot 背景介绍 本公司属于微小型企业,初期业务量不高,所有程序都写在一个maven项目里面,不过是多模块开发. 分了login模块,service模块,cms模 ...
- 2018-08-11 中文代码示例之Spring Boot 2.0.3问好
上次试用Spring Boot还是两年前: 中文代码示例之Spring Boot 1.3.3演示. 打算用在一个讨论组内小项目上, 于是从官网Building an Application with ...
- Java代码自动部署
注:本文来源于<it小熊> [ ①Java代码自动部署-总结简介] 代码部署是每一个软件开发项目组都会有的一个流程,也是从开发环节到发布功能必不可少的环节.对于Java开发者来说,Java ...
- 开发环境,eclipse编辑器java代码自动提示
Eclipse+ADT+Android SDK 搭建安卓开发环境 eclipse编辑器java代码自动提示 window-->Preferences-->JAva-->Content ...
- VsCode搭建Java开发环境(Spring Boot项目创建、运行、调试)
源码地址:https://github.com/YANGKANG01/Spring-Boot-Demo 安装扩展 安装如下两个主要扩展即可,这两个扩展已关联java项目开发主要使用的maven.spr ...
- [转]VsCode搭建Java开发环境(Spring Boot项目创建、运行、调试)
源码地址:https://github.com/YANGKANG01/Spring-Boot-Demo 安装扩展 安装如下两个主要扩展即可,这两个扩展已关联java项目开发主要使用的maven.spr ...
随机推荐
- 关于学习JAVA第二章的心得
这章主要讲了JAVA的变量,数据类型和运算符的使用方法及规则. 其实在大一的时候接触过一点C和C++的知识所以对变量,数据类型,运算符还是有一定了解的. 变量其实就是存储数据的空间.我们每次使用某一种 ...
- Python_每日习题-0008-九九乘法表
题目: 输出9*9乘法口诀表. 程序分析:分行与分列的考虑,共9行9列,i控制行,j控制列. for i in range(1, 10): for j in range(1, i+1): print( ...
- OSS网页上传和断点续传(STSToken篇)
云账号AccessKey拥有所有API访问权限,在客户端不要直接使用,会泄露ak信息,造成安全问题.所以使用STS方式(临时账号权限)给客户端授权. C#版获取STSToken 一.下载阿里SDK(a ...
- elasticsearch聚合操作——本质就是针对搜索后的结果使用桶bucket(允许嵌套)进行group by,统计下分组结果,包括min/max/avg
分析 Elasticsearch有一个功能叫做聚合(aggregations),它允许你在数据上生成复杂的分析统计.它很像SQL中的GROUP BY但是功能更强大. 举个例子,让我们找到所有职员中最大 ...
- PS制作动感酷炫水人街舞照
一.打开原图素材,用钢笔工具把人物从图中扣取出来,新建一个812 * 1024像素的文档,把抠出的人物拖进来,过程如下图. 二.用你习惯的修图工具把人物的手.脸部.腰部.袜子通通修掉.再补回衣服在透视 ...
- .net之httphandler小记
本地调试代码遇到的一个问题,没有走URL路由器(UrlReWriter : IHttpHandlerFactory),于是网上科普了一下原理,主要有两点: 1.asp.net在处理http请求时,会由 ...
- 多线程系列之五:Balking 模式
一,什么是Balking模式 如果现在不合适执行这个操作,或者没必要执行这个操作,就停止处理,直接返回.在Balking模式中,如果守护条件不成立,就立即中断处理. 二,例子: 定期将当前数据内容写入 ...
- 【kindle笔记】之 《活着》-2018-2-5
[kindle笔记]读书记录-总 2018-2-5 今天凌晨一口气看完了<活着>,没想到竟然是个赤裸裸的悲剧,心情不太好地睡去. 福贵,一个小人物,坎坷无比的一生. 当你以为真他妈惨,真是 ...
- 基于CRM跟进(活动)记录中关键字识别的客户跟进加权值的成单概率算法
1.提取销售人员的跟进记录,分析其中的骂人文字(负面情绪),将有负面情绪的客户的跟进排期,进行降权(权重)操作.重点跟进加权值较高的客户. 执行办法: 将销售与客户沟通的语音:电话,微信,QQ,通过调 ...
- MySQL之慢查询日志和通用查询
MySQL中的日志包括:错误日志.二进制日志.通用查询日志.慢查询日志等等.这里主要介绍下比较常用的两个功能:通用查询日志和慢查询日志. 1.通用查询日志:记录建立的客户端连接和执行的语句. 2.慢查 ...