@RequestMapping("biquge")
@ResponseBody
public void biquge() throws Exception {
int i=1;
String name="魔道祖师";
long startTime = System.currentTimeMillis();
//1. 确定首页URL: 魔道小说的第一章的URL
String indexUrl = "https://www.biquge.cc/html/198/198351/1523696.html";
String path="D:\\"+name+".txt";
File file = new File(path);
if(!file.exists()) {
File dir = new File(file.getParent());
dir.mkdirs();
file.createNewFile();
}
//创建一个输出流,将爬到的小说以txt形式保存在硬盘
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path)));
while (true) {
//2. 发送请求, 获取数据
//2.1 创建httpClient对象
CloseableHttpClient httpClient = HttpClients.createDefault();
//2.2 设置请求方式
HttpGet httpGet = new HttpGet(indexUrl);
//2.3 设置请求参数 和请求头
httpGet.setHeader("User-Agent",
"Mozilla/5.0 (Windows NT 6.1; Win64;