zcy19941015
路人甲wttttt
2015-10-11 02:56

python中的xpath,为什么'/html'就匹配不到

  • xpath
  • python
  • html5
 from lxml.html.soupparser import fromstring
import urllib2  
response = urllib2.urlopen('http://www.haojiazhang123.com')  
html = response.read()
root = fromstring(html)    
desc_list = root.xpath('/html/body/div[1]/div[3]/ul/li[2]/a')
print desc_list

但是,把xpath改成'//div[@class="navi"]/ul/li[2]/a'就匹配到了呢?

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答

为你推荐