`
liuzejian4
  • 浏览: 58185 次
  • 性别: Icon_minigender_1
  • 来自: 西安
社区版块
存档分类
最新评论

Parsing a body fragment

 
阅读更多
Problem(问题)
You have a fragment of body HTML (你有一个html片段)(e.g. a div containing a couple of p tags; as opposed to a full HTML document (不是完整的html)) that you want to parse(需要你解析). Perhaps it was provided by a user submitting a comment(也许这是用户提交的评论), or editing the body of a page in a CMS(或编辑一个页面的主体在CMS).

Solution(解决)
Use the Jsoup.parseBodyFragment(String html) method(你可以使用Jsoup.parseBodyFragment(String html) 这个方法).

String html = "<div><p>Lorem ipsum.</p>";
Document doc = Jsoup.parseBodyFragment(html);
Element body = doc.body();

Description(描述)
The parseBodyFragment method creates an empty shell document(parseBodyFragment的方法会创建一个空的文档), and inserts the parsed HTML into the body element(和插入解析HTML body元素的). If you used the normal Jsoup.parse(String html) method(你是用正常的Jsoup.parse(String html)), you would generally get the same result(你通常会得到同样的结果), but explicitly treating the input as a body fragment ensures that any bozo HTML provided by the user is parsed into the body element(但显式地处理输入,作为主体片段确保任何用户提供的HTML body元素被解析).

The Document.body() method retrieves the element children of the document's body element(Document.body()方法检索子元素body); it is equivalent to doc.getElementsByTag("body")(它相当于doc.getElementsByTag("body")).

Stay safe
If you are going to accept HTML input from a user(如果你要接受HTML用户输入), you need to be careful to avoid cross-site scripting attacks. See the documentation for the Whitelist based cleaner(你需要小心避免跨站点脚本攻击。请参阅文档的白名单基于清洁), and clean the input with clean(和过滤输入)(String bodyHtml, Whitelist whitelist(字符串html和白名单)).
分享到:
评论

相关推荐

    sdilreade(Parsing the IL of a Method Body)

    how to get a readable and programmable result from the IL array provided by the MethodBody.GetILAsByteArray() method.

    挂机,你离开一下为了不让他人动你电脑就现在开始把

    用于离开挂机行好挂机。你离开一下为了不让他人动你电脑就现在开始把

    Parsing Techniques - A Practical Guide

    ### Parsing Techniques - A Practical Guide (第二版) #### 知识点概述 《Parsing Techniques - A Practical Guide》(第二版)是一本深入浅出地介绍解析器技术的专业书籍。相较于经典的“龙书”,本书以其通俗...

    Parsing Techniques:A Practical Guide

    ### Parsing Techniques:A Practical Guide — 关键知识点概览 #### 一、引言与背景介绍 《Parsing Techniques:A Practical Guide》是一本详细介绍解析技术的著作,由Dick Grune和Ceriel J. Jacobs共同撰写。该书...

    clothes_parsing, 纸张'A High Performance CRF Model for Clothes Parsing'的代码.zip

    clothes_parsing, 纸张'A High Performance CRF Model for Clothes Parsing'的代码 衣服解析概述这里代码提供了研究论文的实现: A High Performance CRF Model for Clothes Parsing Edgar Simo-Serra, Sanja Fidler...

    Parsing Techniques: A Practical Guide (Monographs in Computer Science)

    They are used in a variety of software products including Web browsers, interpreters in computer devices, and data compression programs; and they are used extensively in linguistics.

    Parsing with Perl 6 Regexes and Grammars A Recursive Descent into Parsing epub

    Parsing with Perl 6 Regexes and Grammars A Recursive Descent into Parsing 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书

    ParsingTechniques--a practical guide.pdf

    ### Parsing Techniques: A Practical Guide #### 核心知识点解析 **1. 解析技术概览** - **定义与重要性:** 解析技术(Parsing)是计算机科学中的一个重要领域,主要关注如何将输入字符串转换为有意义的数据...

    整理的一些human parsing数据集

    数据集包括:ATR(human parsing)、LIP(Looking into Person)、Multi-human-parsing数据集。基本山涵盖了所有国际公开的human parsing数据集!

    Parsing Techniques a Practical Guide

    ### Parsing Techniques: A Practical Guide — 关键知识点概览 #### 一、书籍介绍与目标读者 《Parsing Techniques: A Practical Guide》是一本详细介绍解析技术的实用指南,旨在为程序员、语言学家以及对语法分析...

    解析技术-实用指南Parsing Techniques - A Practical Guide

    对许多不同的解析技术及其相互关系和适用性(包括错误恢复技术)进行了清晰,可访问且透彻的讨论。

    Trends in Parsing Technology

    - Harry Bunt, Paola Merlo, Joakim Nivre 编辑的《Trends in Parsing Technology》 - Nancy Ide, Vassar College, New York 和 Jean Véronis, Université de Provence and CNRS, France 系列编辑的《Text, Speech...

    Parsing JSON in Swift

    Parsing JSON in Swift will teach you to harness the power of Swift and give you confidence that your app can gracefully handle any JSON that comes its way. You'll learn: - How to use ...

    Parsing Techniques 原装扫描

    《Parsing Techniques》是一本深入探讨解析技术的权威著作,对于学习和理解编译原理的高级概念至关重要。在编程语言的设计与实现中,解析是至关重要的一步,它将源代码转换为计算机可以理解的形式。这本书详细介绍了...

    Parsing techiniques A Practical Guide

    标题《Parsing Techniques: A Practical Guide》所指向的是编译原理领域中的一个重要分支——解析技术。解析技术在编译器设计中占据核心地位,其任务是将源代码转化为中间代码,这个过程需要程序代码能够被计算机...

    parsing algorithm

    "parsing algorithm"指的是用于分析和理解句子结构的程序或方法,它的目标是将一段文本分解成可解释的语法单元,以便更好地理解其含义。在这个过程中,每一个"node"代表句子中的一个语法成分,如单词、短语或者从句...

    前端开源库-parsing

    "前端开源库-parsing"着重关注的是解析技术,特别是基于JSON语法的解析器。JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,因其易读易写、机器可读性强的特点,在网络数据传输中广泛应用。本文将...

    Parsing Techniques, 2nd Edition_含目录.pdf

    Parsing Techniques, 2nd Edition_含目录.pdf, 带目录的版本

Global site tag (gtag.js) - Google Analytics