Skip to content

Latest commit

 

History

History
26 lines (18 loc) · 617 Bytes

File metadata and controls

26 lines (18 loc) · 617 Bytes

scrapy的spider打开shell用于调试xpath的方法

from scrapy.shell import inspect_response
inspect_response(response, self)

xpath函数normalize-space()的功能是去掉前后的空格,有两种用法:

第一种方法非常实用,normalize-space用在属性上,如

response.xpath("//div[normalize-space(@class)='nav']/text()")

第二种方法:normalize-space用结果上,如

response.xpath("normalize-space(//div[normalize-space(@class)='nav']/text())")

提取html所有文本的最简单方法

response.xpath("string(.)")