zoukankan      html  css  js  c++  java
  • scrapy:get cookie from response

    scrapy shell
    fetch('your_url')
    response.headers.getlist("Set-Cookie")
    https://stackoverflow.com/questions/46543143/scrapy-get-cookies-from-response-request-headers
     response.headers 返回所有的headers
     response.headers.get("Set-Cookie") 返回的是byte类型
    b'token=P85TRJJ1C7; expires=Wed, 27-Feb-2019 01:54:18 GMT; Max-Age=30; Path=/'
     response.headers.getlist("set-cookie")

    [b'__cfduid=d725f0c6f730503571750709bcce5339e1551232427; expires=Thu, 27-Feb-20 01:53:47 GMT; path=/; domain=.scrapingclub.com; HttpOnly',

    b'token=P85TRJJ1C7; expires=Wed, 27-Feb-2019 01:54:18 GMT; Max-Age=30; Path=/']

    b'表示是byte,
    response.headers.get("Set-Cookie").decode("utf-8")  可以encode成sentence
    pa=re.compile('token=(.*?);')
    
    pa.findall( response.headers.get("set-cookie").decode("utf-8")) 返回的是list列表,用[0]get内容
    headers 没有带x-requested-with:XMLHttpRequest 
    请求不成功,带上之后请求成功
    可以用来判断客户端的请求是Ajax请求还是其他请求。。
    若 req.headers['x-requested-with'].toLowerCase() == 'xmlhttprequest' 则为ajax请求。
    
    
    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- focus on what you want to be
  • 相关阅读:
    流程控制和数组
    数据类型和运算符
    JavaWeb(一)-Servlet中的Config和Context
    成语接龙
    java 解决树形结构数据 (有序无序通杀)
    java https
    git 使用教程
    Spring boot 解决跨域问题
    redis详解(四)--高可用分布式集群
    redis详解(三)--面试题
  • 原文地址:https://www.cnblogs.com/bamboozone/p/10441769.html
Copyright © 2011-2022 走看看