>>> response.xpath('html/body/title/text()')
[]
表示的路径如下
html ----> html ----> body ----> title ----> text
由于出现了两个html,所以搜索不到。
下面给出三种写法:
1 从子节点开始的
>>> response.xpath('body/title/text()')
2 从根节点开始的
>>> response.xpath('/html/body/title/text()')
3 从任意节点开始的
>>> response.xpath('//body/title/text()')
>>> response.xpath('//html/body/title/text()')