Skip to content

Commit

Permalink
Merge pull request #4 from Curious-chen/main
Browse files Browse the repository at this point in the history
feat: 支持目录页解析详情地址
  • Loading branch information
unclezs committed Jul 10, 2023
2 parents 2a4aa0b + 65c16ba commit 6f54c14
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<dependency>
<groupId>com.unclezs</groupId>
<artifactId>novel-analyzer</artifactId>
<version>1.0.27</version>
<version>1.0.28</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<name>novel-analyzer</name>
<groupId>com.unclezs</groupId>
<artifactId>novel-analyzer</artifactId>
<version>1.0.27</version>
<version>1.0.28</version>

<url>https://github.com/unclezs/novel-analyzer</url>
<description>Uncle小说解析 SDK</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public class TocRule implements Verifiable, Serializable {
* 章节链接
*/
private CommonRule url;
/**
* 章节详情页规则
*/
private CommonRule detailPage;
/**
* 章节下一页规则(存在则会匹配下一页)
*/
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/com/unclezs/novel/analyzer/spider/TocSpider.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.unclezs.novel.analyzer.core.comparator.ChapterComparator;
import com.unclezs.novel.analyzer.core.helper.AnalyzerHelper;
import com.unclezs.novel.analyzer.core.helper.DebugHelper;
import com.unclezs.novel.analyzer.core.matcher.Matchers;
import com.unclezs.novel.analyzer.core.matcher.matchers.RegexMatcher;
import com.unclezs.novel.analyzer.core.model.AnalyzerRule;
import com.unclezs.novel.analyzer.core.model.TocRule;
Expand Down Expand Up @@ -190,7 +191,17 @@ protected boolean loadPage(int page) throws IOException {
try {
// 解析小说详情,从目录页
if (page == 1) {
this.novel = NovelMatcher.details(originalText, rule.getDetail());
String detailPageUrl = Matchers.match(originalText, tocRule.getDetailPage());
// 如果详情页不为空,则请求详情页
if (StringUtils.isNotBlank(detailPageUrl) && !detailPageUrl.equals(params.getUrl())) {
// 默认使用目录页的请求参数
RequestParams detailParams = RequestParams.create(detailPageUrl, rule.getToc().getParams());
String detailText = SpiderHelper.request(rule.getParams(), detailParams);
this.novel = NovelMatcher.details(detailText, rule.getDetail());
} else {
// 否则,从目录页解析详情
this.novel = NovelMatcher.details(originalText, rule.getDetail());
}
this.novel.setUrl(params.getUrl());
}
List<Chapter> chapters = NovelMatcher.toc(originalText, tocRule);
Expand Down

0 comments on commit 6f54c14

Please sign in to comment.