标签:usr pat python parse port imp img == html
#!/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‘)
标签:usr pat python parse port imp img == html
原文地址:https://www.cnblogs.com/gerenboke/p/13389022.html