子孙所有内容
response.selector.xpath("//")
子孙中id属性=images
response.selector.xpath("//[@id=‘image’]")
子孙中id属性=images内a节点包含的文本
response.selector.xpath("//*[@id=‘image’]/a/text()")
以上生成的均为selectorlist
取所有,生成所要元素的list
response.xpath("//[@id=‘images’]/a/text()").extract()
取第一个
response.xpath("//[@id=‘images’]/a/text()").extract_first()
response.xpath("//*[@id=‘images’]/a/text()").extract_first(‘default’)
嵌套选择
result = response.xpath("//*[@id=‘images’]/a")
r2 = response.xpath(‘img’)
r3 = response.xpath(’./img’)
从根节点
r4 = response.xpath(’/img’)
for i in r4:
print(i.extract())
获取属性值
r2.xpath(’./@src’).extract()