From 58bda2baf2a6cac5bd3b1a241a019f7355c2bdc3 Mon Sep 17 00:00:00 2001 From: Haleydu <44172947+Haleydu@users.noreply.github.com> Date: Tue, 11 Aug 2020 18:56:07 +0800 Subject: [PATCH] fix dongmanmanhua ,closed #57 --- .../cimoc/source/WebtoonDongManManHua.java | 50 ++++++++++++------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/hiroshi/cimoc/source/WebtoonDongManManHua.java b/app/src/main/java/com/hiroshi/cimoc/source/WebtoonDongManManHua.java index 25595c96..59304646 100644 --- a/app/src/main/java/com/hiroshi/cimoc/source/WebtoonDongManManHua.java +++ b/app/src/main/java/com/hiroshi/cimoc/source/WebtoonDongManManHua.java @@ -90,31 +90,47 @@ public void parseInfo(String html, Comic comic) { comic.setInfo(title, cover, update, intro, author, status); } + public List parseChapter(Node body){ + List list = new LinkedList<>(); + for (Node node : body.list("ul#_listUl > li > a")) { + String title = node.text("span.subj > span")+" "+node.text("span.tx"); + String path = "https:" + node.href(); + list.add(new Chapter(title, path)); + } + return list; + } + @Override public List parseChapter(String html) { + //下次再优化吧,这样写比较容易但是效率低。 List list = new LinkedList<>(); Node body = new Node(html); for (Node nodePage : body.list("div.detail_lst > div.paginate > a")) { String urlPage = nodePage.href(); - if (urlPage.equals("#")){ - for (Node node : body.list("ul#_listUl > li > a")) { - String title = node.text("span.subj > span"); - String path = "https:" + node.href(); - list.add(new Chapter(title, path)); + String urlPageTag = nodePage.attr("a","class"); + if (urlPage.equals("#") && (urlPageTag==null || urlPageTag.equals(""))){ + list.addAll(parseChapter(body)); + }else if (urlPageTag==null || urlPageTag.equals("")){ + try { + String pageTagUrl = baseUrl + urlPage; + Request request = new Request.Builder() + .url(pageTagUrl) + .addHeader("Referer", "www.dongmanmanhua.cn") + .build(); + String htmlPage = getResponseBody(App.getHttpClient(), request); + list.addAll(parseChapter(new Node(htmlPage))); + } catch (Manga.NetworkErrorException e) { + e.printStackTrace(); } - }else { + }else if (urlPageTag.equals("pg_next")){ try { - String htmlPage = getResponseBody( - App.getHttpClient(), - new Request.Builder().url(baseUrl + urlPage) - .addHeader("Referer", "www.dongmanmanhua.cn") - .build()); - Node bodyPage = new Node(htmlPage); - for (Node node : bodyPage.list("ul#_listUl > li > a")) { - String title = node.text("span.subj > span"); - String path = "https:" + node.href(); - list.add(new Chapter(title, path)); - } + String pageTagUrl = baseUrl + urlPage; + Request request = new Request.Builder() + .url(pageTagUrl) + .addHeader("Referer", "www.dongmanmanhua.cn") + .build(); + String htmlPageNext = getResponseBody(App.getHttpClient(), request); + list.addAll(parseChapter(htmlPageNext)); } catch (Manga.NetworkErrorException e) { e.printStackTrace(); }