python 使用lxml解析html(xpath)

举个栗子好了:

#coding:utf-8
import urllib2
from  lxml import etree





f = urllib2.urlopen("http://www.ydylcn.com/skwx_ydyl/sublibrary?ID=8724&SiteID=1&showDetail=true&RootFlag=Y") 
conent = f.read()
article_name = etree.HTML(conent)
print article_name.xpath("//div[@class='zt_list'][1]/h2/a/text()")[0]


重点就是,使用lxml.etree.HTML

你可能感兴趣的:(python 使用lxml解析html(xpath))