Search in sources :

Example 1 with Porn91ForumContent

use of com.dante.data.model.Porn91ForumContent in project 91Pop by DanteAndroid.

the class ParseForum91Porn method parseContent.

public static BaseResult<Porn91ForumContent> parseContent(String html, boolean isNightModel, String baseUrl) {
    BaseResult<Porn91ForumContent> baseResult = new BaseResult<>();
    Document doc = Jsoup.parse(html);
    Element content = doc.getElementsByClass("t_msgfontfix").first();
    if (content == null) {
        List<String> stringList = new ArrayList<>();
        Porn91ForumContent porn91ForumContent = new Porn91ForumContent();
        porn91ForumContent.setImageList(stringList);
        porn91ForumContent.setContent("暂不支持解析该网页类型或者帖子已被封禁了");
        baseResult.setData(porn91ForumContent);
        return baseResult;
    }
    Logger.t(TAG).d(content);
    Elements attachPopups = doc.getElementsByClass("imgtitle");
    if (attachPopups != null) {
        for (Element element : attachPopups) {
            element.html("");
        }
    }
    // 去掉段落样式
    Elements ps = content.select("p");
    for (Element p : ps) {
        p.attr("style", "");
    }
    // 去掉字体大小以及适配夜间模式
    Elements fonts = content.select("font");
    for (Element font : fonts) {
        font.attr("style", "font-size: 16px");
        font.attr("size", "3");
        if (isNightModel) {
            font.attr("color", "#5ACC87");
        }
    }
    // 调整图片
    Elements imagesElements = content.select("img");
    List<String> stringList = new ArrayList<>();
    for (Element element : imagesElements) {
        String imgUrl = element.attr("src");
        // 只替换不为空且结尾为.jpg 但链接不完整的
        if (!TextUtils.isEmpty(imgUrl) && imgUrl.endsWith(".jpg") && !imgUrl.startsWith("http")) {
            imgUrl = baseUrl + imgUrl;
            element.attr("src", imgUrl);
            stringList.add(imgUrl);
        } else if (!TextUtils.isEmpty(element.attr("file"))) {
            imgUrl = baseUrl + element.attr("file");
            element.attr("src", imgUrl);
            stringList.add(imgUrl);
        }
        element.attr("width", "100%");
        element.attr("style", "margin-top: 1em;");
        element.attr("alt", "[图片无法加载...]");
        element.attr("onclick", "HostApp.toast(\"" + imgUrl + "\")");
    }
    Porn91ForumContent porn91ForumContent = new Porn91ForumContent();
    String contentStr = content.html().replace("<dd", "<dt").replace("</dd>", "</dt>");
    porn91ForumContent.setContent(contentStr);
    porn91ForumContent.setImageList(stringList);
    baseResult.setData(porn91ForumContent);
    return baseResult;
}
Also used : BaseResult(com.dante.data.model.BaseResult) Porn91ForumContent(com.dante.data.model.Porn91ForumContent) Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements)

Aggregations

BaseResult (com.dante.data.model.BaseResult)1 Porn91ForumContent (com.dante.data.model.Porn91ForumContent)1 ArrayList (java.util.ArrayList)1 Document (org.jsoup.nodes.Document)1 Element (org.jsoup.nodes.Element)1 Elements (org.jsoup.select.Elements)1