class MyspiderMiddleware(object):
def __init__(self):
pass
self.headers = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36",
"Referer": "https://wx.zsxq.com/dweb/", "Authorization": "055E0C37-0002-6E26-E861-BE4E96B07E5B"}
self.cookies_str = "upload_channel=qiniu; access_token=055E0C37-0002-6E26-E861-BE4E96B07E5B; ws_address=wss%3A//ws.zsxq.com%3A443/ws%3Fversion%3Dv1.10%26access_token%3D055E0C37-0002-6E26-E861-BE4E96B07E5B; user_id=28518554421821; name=%u5411%u7FD4; avatar_url=https%3A//images.zsxq.com/FhlMwwUVUJY9NJmuyX67a-EAEZXa%3Fe%3D1874736000%26token%3DkIxbL07-8jAj8w1n4s9zv64FuZZNEATmlU_Vm6zD%3AXNDj34S3Cnck9im2BQniBQZvtvI%3D; UM_distinctid=16588c8f68a888-0a0f61af94adcb-163b6953-13c680-16588c8f68b15e; CNZZDATA1256787036=746628557-1535593524-null%7C1536599179"
def process_request(self, request, spider):
-sharp RequestheaderUser-Agent
request.headers.setdefault("User-Agent", self.headers)
request.headers.setdefault("cookies", self.get_cookies(self.cookies_str))
def get_cookies(self, cookies_str):
cookies = {}
for line in cookies_str.split(";"): -sharp :
-sharp 12
name, value = line.strip().split("=", 1)
cookies[name] = value -sharp cookies
return cookies
I feel that I didn"t pass the cookie through