1 2 Fork me on GitHub 6

scrapy shell 的使用

是什么?:是一个终端下的调试工具,用来调试scrapy

安装ipython :pip install ipython

启动: scrapy shell + 需要请求的url

进来之后,response就是响应对象,可以直接使用

  • response.text
  • response.body
  • response.url
  • response.headers
  • response.status
  • response.xpath()
    无论xpath路径是精确到节点还是属性,它返回的永远都是scrapy自己封装的selector对象,要提取内容,就要通过extract()来进行提取,
    response.xpath('xxx').extract()[0] == response.xpath('xxx')[0].extract() == response.xpath('xxx').extract_first()
    extract_first()比上面的两个要智能,如果xpath写错了,上面两个会报错,extract_first会返回None
posted @ 2020-05-06 16:58  peng_li  阅读(227)  评论(0)    收藏  举报
1