爬虫-用lxml解析HTML,用xpath()方法提取数据

本文介绍了如何使用Python的lxml库解析HTML和XML文档,重点讲解了lxml提供的不同解析器和常用方法,如etree.fromstring(), etree.parse(), etree.XML(), 和etree.HTML()。同时,文章强调了XPath在信息抽取中的作用,并给出了XPath的基本用法,包括节点选择、属性匹配等。" 113967842,10535881,CentOS源码安装MySQL5.6教程,"['测试环境搭建', '数据库', 'MySQL', 'Linux', '软件测试']
摘要由CSDN通过智能技术生成

未完待续      

一、学习网站

1.https://lxml.de/

https://lxml.de/xpathxslt.html#xpath-return-values

2.https://www.w3.org/TR/xpath/all/ 

二、lxml - XML and HTML with Python

lxml is the most feature-rich and easy-to-use library for processing XML and HTML in the Python language.

Parsers are represented by parser objects. There is support for parsing both XML and (broken) HTML. Note that XHTML is best parsed as XML, parsing it with the HTML parser can lead to unexpected results. 

2.1可使用的解析器

可使用的解析器有:lxml.etree.XMLParser()和lxml.etree.HTMLParser()我们可以通过etree中的方法来调用它们,先来看解析器

1.class lxml.etree.XMLParser()

class lxml.etree.XMLParser(selfencoding=Noneattribute_defaults=Falsedtd_validation=Falseload_dtd=Falseno_network=Truens_clean=Falserecover=Falseschema: XMLSchema = Nonehuge_tree=Falseremove_blank_text=Falseresolve_entities=Trueremove_comments=Falseremove_pis=Falsestrip_cdata=Truecollect_ids=Truetarget=Nonecompact=True)

Bases: lxml.etree._FeedParser

The XML parser.

Parsers can be supplied as additional argument to various parse functions of the lxml API. A default parser is always available and can be replaced by a call to the global function ‘set_default_parser’. New parsers can be created at any time without a major run-time overhead.

详细说明见:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值