xpath解析基础
Posted gerenboke
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了xpath解析基础相关的知识,希望对你有一定的参考价值。
#!/usr/bin/python
from lxml import etree
if __name__ == "__main__":
#实例化一个etree对象,且将被解析的源码加载到了该对象中
tree = etree.parse(‘test.html‘)
r = tree.xpath(‘./html/body/div‘)
r = tree.xpath(‘./html//div‘)
r = tree.xpath(‘//div‘)
tree.xpath(‘//div[@class="song"]‘)
tree.xpath(‘//div[@class="song"]/p[3]‘)
tree.xpath(‘//div[@class="song"]//li[5]/a/text()‘)[0]
tree.xpath(‘.//li[7]//text()‘)
tree.xpath(‘//div[@class="song"]/img/@src‘)
以上是关于xpath解析基础的主要内容,如果未能解决你的问题,请参考以下文章