Nmap PaddleHub lua playframework pyqt swiftui vue router 郑州小程序公司 jquery查找子元素 kafka默认端口 db2从入门到精通 spark文档 axure时间选择控件 车载u盘 python的数据类型 python课程 pythoninput python重复执行 python的开发工具 java数据类型 java正则表达式用法 java正则表达式匹配 java开发教程 java数组添加 java方法 java的map java学习课程 java文件路径 java字符 高等数学同济第七版 神龙激活 微信小程序提示框 完美手游模拟器 millenium u盘系统下载 思源字体 mac强制重启 medcalc 幽灵行动多少钱 renderpartial
当前位置: 首页 > 学习教程  > 编程语言

理解lxml module in Python

2020/12/5 9:48:09 文章标签:

Overview homepage Python 爬虫利器三之 Xpath 语法与 lxml 库的用法 The ElementTree XML API in Python The lxml XML toolkit is a Pythonic binding for the C libraries libxml2 and libxslt. It is unique in that it combines the speed and XML feature completeness o…

  • Overview

    homepage

    Python 爬虫利器三之 Xpath 语法与 lxml 库的用法

    The ElementTree XML API in Python

    The lxml XML toolkit is a Pythonic binding for the C libraries libxml2 and libxslt. It is unique in that it combines the speed and XML feature completeness of these libraries with the simplicity of a native Python API, mostly compatible but superior to the well-known ElementTree API. The latest release works with all CPython versions from 2.7 to 3.9.

  • Tutorial

    • the lxml.etree tutorial for XML processing
    • John Shipman’s tutorial on Python XML processing with lxml
    • Fredrik Lundh’s tutorial for ElementTree
    pip install lxml
    from lxml import etree
    root = etree.Element("root")
    root.append(etree.Element("child1"))
    child2 = etree.SubElement(root, "child2")
    chile3 = etree.SubElement(root, "child3")
    # Elements are lists
    child = root[0]
    root[0].getparent()
    etree.tostring(root)
    # Elements carry attributes as a dict
    root1 = etree.Element("root", interesting="totally")
    root1.get("interesting")
    root1.set("hello","Huhu")
    etree.tostring(root)
    root1.keys()# display all the attributes
    root1.attrib # return a dict
    # Elements contain text
    root2 = etree.Element("root")
    root2.text = "TEXT"
    etree.tostring(root2,with_tail=False,method="text")
    ####### Using XPath to find text
    html.xpath("string()")
    html.xpath("//text()")
    

本文链接: http://www.dtmao.cc/news_show_450085.shtml

附件下载

相关教程

    暂无相关的数据...

共有条评论 网友评论

验证码: 看不清楚?