本帖最后由 迷途的懒虫 于 2023-1-4 14:56 编辑
流程:
1.先根据id抓取所有zxcs仙草数量
2.将过滤后的书籍重排序
3.根据id获取书籍名称
可根据自己喜好,修改逻辑简便使用,注意访问频率(引用了hutool包)
补充注释,附 仙草大于1000的书籍
[JavaFX] 纯文本查看 复制代码 public static void main(String[] args) {
String scoreUrl = "http://zxcs.me/content/plugins/cgz_xinqing/cgz_xinqing_action.php?action=show&id=";
String contentUrl = "http://zxcs.me/post/";
String downloadUrl = "http://zxcs.me/download.php?id=";
//max 12300
List<String> scoreList = new ArrayList<>();
for (int i = 0; i < 12300; i++) {
//获取评分
HttpResponse response = HttpRequest.get(scoreUrl + i).execute();
if (!response.isOk()) {
continue;
}
String text = response.body();
//解析仙草数,过滤低于1000的
int good = Convert.toInt(text.split(",")[0], -1);
if (good < 1000) {
continue;
}
scoreList.add(good + "-" + i);
}
//根据仙草数重排序
scoreList.sort((a, b) -> b.compareTo(a));
FileUtil.writeLines(scoreList, "E:\\zxcsScore.txt", "utf-8");
List<String> titleList = new ArrayList<>();
for (String item : scoreList) {
String[] str = item.split("-");
String id = str[1];
//请求获取书名
HttpResponse resp = HttpRequest.get(contentUrl + id).execute();
if (!resp.isOk()) {
continue;
}
String text2 = resp.body();
//书名解析
String title = text2.substring(text2.indexOf("<title>《") + 7, text2.indexOf("》") + 1);
titleList.add(title + ", id:" + id + ", good:" + str[0]);
}
//保存结果
String path = "E:\\zxcs.txt";
String charset = "utf-8";
FileUtil.writeString(downloadUrl, path, charset);
FileUtil.writeLines(titleList, path, charset, true);
}
|