java实现小说采集_Java实现一个小说采集程序的简单实例
Java實現一個小說采集程序的簡單實例
發布于 2021-1-7|
復制鏈接
下面小妖就為大家帶來一篇Java實現一個小說采集程序的簡單實例。小妖覺得挺不錯的, 現在就分享給大家,也給大家做個參考。一起跟隨小妖過來看看吧
被標題吸引進來的不要罵我。只是一個簡單的實現,隨手寫了來下載一部喜歡的小說的。示例中的小說只是示例,不是我的菜。使用了jsoup。挺好用的一個工具。有需要的話,參考下自己改吧。挺簡單的,是吧。代碼如下:
```java
package com.zhyea.doggie;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
public class Doggie {
public static void main(String[] args){
try{
File txtFile = new File("D:/無限崩壞.txt");
createTxtDoc(txtFile);
addContent(txtFile);
}catch(Exception e){
e.printStackTrace();
}
}
/**
* 向小說文件中添加內容
* @param txtFile
* 小說文件
* @throws IOException
* @throws InterruptedException
*/
private static void addContent(File txtFile) throws IOException, InterruptedException{
appendTxt(txtFile, getBookInfo("無限崩壞", "啪啪啪狂魔"));
String url = "http://www.83kxs.com/View/12/12653/{pattern}.html";
for(int i=5850686; i", "")
.replaceAll("", "")
.replaceAll("\\", "")
.replaceAll("?", "")
.replaceAll("", NEWLINE)
+ NEWLINE;
return rtn;
}
/**
* 創建新的txt文件
* @param fullName
* 文件全名
* @return
* @throws Exception
*/
private static boolean createTxtDoc(File txtFile) throws Exception{
try{
return txtFile.createNewFile();
}catch(Exception e){
throw e;
}
}
/**
* 向txt文件中追加內容
* @param txtFile
* 要操作的txt文件
* @param content
* 要追加的內容
* @throws IOException
*/
private static void appendTxt(File txtFile, String content) throws IOException{
FileWriter writer = null;
try{
writer = new FileWriter(txtFile, true);
writer.append(content);
}finally{
if(null!=writer)writer.close();
}
}
/**
* 換行符
*/
static final String NEWLINE = System.getProperty("line.separator");
/**
* 書前的通用信息
*/
static String COMMON = "------------------------------------------------------------------" + NEWLINE
+ "--------------- 書名:{book}" + NEWLINE
+ "--------------- 作者:{author}" + NEWLINE
+ "--------------- zhyea.com" + NEWLINE
+ "------------------------------------------------------------------" + NEWLINE;
}
```
總結
以上是生活随笔為你收集整理的java实现小说采集_Java实现一个小说采集程序的简单实例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 6工程文件夹作用_data_dragon
- 下一篇: linux 驱动没有设备id,linux