python中的xpath,为什么'/html'就匹配不到
fromlxml.html.soupparserimportfromstringimporturllib2response=urllib2.urlopen('http:/...
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'就匹配到了呢? 展开
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'就匹配到了呢? 展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励30(财富值+成长值)
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询