Python_API_Structured Markup Processing Tools_sgmllib.SGMLParser

本文介绍了Python中SGMLParser类的基本用法及其在解析HTML文档中的应用。SGMLParser可以解析SGML格式的文本文件,并支持HTML标签、特殊字符引用、实体引用及注释的解析。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

API文档:

    This module defines a class SGMLParser which serves as the basis for parsing text files formatted in SGML (Standard Generalized Mark-up Language). In fact, it does not provide a full SGML parser — it only parses SGML insofar as it is used by HTML, and the module only exists as a base for the htmllib module. Another HTML parser which supports XHTML and offers a somewhat different interface is available in the HTMLParser module.

class sgmllib.SGMLParser      The SGMLParser class is instantiated without arguments. The parser is hardcoded to recognize the following constructs:              
  • Opening and closing tags of the form <tag attr="value" ...> and </tag>, respectively.
  • Numeric character references of the form &#name;.
  • Entity references of the form &name;.
  • SGML comments of the form <!--text-->. Note that spaces, tabs, and newlines are allowed between the trailing > and the immediately preceding --.




翻译文档:

      这个模块定义了一个SGMLParser类,这个类提供了解析SGML(标准通用标示语言)的功能。

但是他并没有提供完整的对SGML的解析功能。这个模块只是为htmllib模块定义了一个基本的方法。这个HTMLParser模块定义了以写可解析XHTML的方法和其他功能。

     这个SGMLParser类是不带参数的实例。可通过编码接卸如下文档结构:

         可分别标签开始和结束。例如 :<tag attr="value" ...> and </tag>,

         特殊字符引用。例如:&#name;.等,16进制字符转化等

         实体引用。例如:html&copy

        注释:<!--->


    

   


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值