-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
73 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.pcdd.sonovel.parse; | ||
|
||
import cn.hutool.core.util.URLUtil; | ||
import cn.hutool.setting.dialect.Props; | ||
import com.pcdd.sonovel.model.Chapter; | ||
import com.pcdd.sonovel.util.Settings; | ||
import lombok.SneakyThrows; | ||
import org.jsoup.Jsoup; | ||
import org.jsoup.nodes.Document; | ||
import org.jsoup.select.Elements; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* @author pcdd | ||
*/ | ||
public class CatalogParser extends Parser { | ||
|
||
public static final String INDEX_URL; | ||
|
||
// 加载配置文件参数 | ||
static { | ||
Props sys = Settings.sys(); | ||
INDEX_URL = sys.getStr("index_url"); | ||
} | ||
|
||
public CatalogParser(int sourceId) { | ||
super(sourceId); | ||
} | ||
|
||
@SneakyThrows | ||
public List<Chapter> parse(String url, int start, int end) { | ||
Document document = Jsoup.parse(URLUtil.url(url), 30_000); | ||
Elements elements = document.selectXpath(this.rule.getBook().getCatalog()); | ||
List<Chapter> catalog = new ArrayList<>(); | ||
|
||
for (int i = start - 1; i < end && i < elements.size(); i++) { | ||
Chapter build = Chapter.builder() | ||
.title(elements.get(i).text()) | ||
.url(INDEX_URL + elements.get(i).attr("href")) | ||
.chapterNo(i + 1) | ||
.build(); | ||
catalog.add(build); | ||
} | ||
|
||
return catalog; | ||
} | ||
|
||
public static void main(String[] args) { | ||
new CatalogParser(1).parse("https://www.xbiqugu.info/66/66747/", 1, 50); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters