• Atitit.jsou html转换纯文本 java c# php


    Atitit.jsou html转换纯文本 java c# php

     

    1原理<p> <h> <li><div> lable转换为回车1

    2调用2

    3Php的实现strip_tags2

    4参考2

     

    1. 原理<p> <h> <li><div> lable转换为回车

     

       "'&(quot|#34);'i", // 替换 HTML 实体

    作者:: 绰号:老哇的爪子 ( 全名::Attilax Akbar Al Rapanui 阿提拉克斯 阿克巴 阿尔 拉帕努伊 ) 汉字名:艾龙,  EMAIL:1466519819@qq.com

    转载请注明来源: http://blog.csdn.net/attilax

     

     

    public void head(Node nodeint depth) {

    String name = node.nodeName();

    if (node instanceof TextNode)

    append(((TextNode) node).text());

    else if (name.equals("li"))

    append("  * ");

    }

     

    public void tail(Node nodeint depth) {

    String name = node.nodeName();

    if (name.equals("br"))

    append(" ");

    else if (StringUtil.in(namenew String[] { "p""h1""h2""h3",

    "h4""h5" }))

    append(" ");

    else if (name.equals("a"))

    append(String.format(" <%s>",

    new Object[] { node.absUrl("href") }));

    }

     

    private void append(String text)

     

     

    2. 调用

    public static void main(String[] args) {

    pathx.isWebPathMode = true;

    String f = pathx.classPath() + "/com/attilax/cms/cms_tmplt.html";

    String txt = filex.read(f);

    Document doc = Jsoup.parse(txt);

    // Document doc = Jsoup.connect(url).get();

    String plainText;

    HtmlToPlainText formatter = new HtmlToPlainText();

    plainText = formatter.getPlainText(doc);

    System.out.println(plainText);

     

    String x = "工作时间:08:00-22:00 性别要求:男女不限";

    x = plainText;

    @SuppressWarnings("rawtypes")

    Map m = new RowParser().parse(x);

    System.out.println(AtiJson.toJson(m));

    System.out.println("---f");

     

    }

     

    3. Php的实现strip_tags

    string strip_tags(string str[,string allowable_tags])

    4. 参考

     

    Jsoup代码解读之一-概述 - ImportNew.htm

    PHPHTML转换成纯文本内容实例-Php常用代码-Php教程-壹聚教程网.htm

  • 相关阅读:
    kaggle CTR预估
    基于大规模语料的新词发现算法【转自matix67】
    vim E437: terminal capability "cm" required
    makefile 中的符号替换($@、$^、$<、$?)
    【转】Makefile 中:= ?= += =的区别
    python urljoin问题
    python 写文件刷新缓存
    python Popen卡死问题
    nohup 日志切割
    换行和回车野史
  • 原文地址:https://www.cnblogs.com/attilax/p/5963481.html
Copyright © 2020-2023  润新知