如何使用headless chrome
从请求标头返回Cookie?
这是来自HAR文件的对象:
{
"startedDateTime": "2017-10-16T22:52:59.382Z",
"time": 218.02899999602226,
"request": {
"method": "GET",
"url": "http://www.allstate.com/",
"httpVersion": "HTTP/1.1",
"headers": [
{
"name": "User-Agent",
"value": "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"
},
{
"name": "cookie",
"value": "ak_bmsc=48DEF0C13393490FCEB2FDA5A4A47272D17497C42A7F0000DB37E559BE40FA5A~plKzlrqFeBqHoExIu4hYna8WskNf3a/28W7xdb5+d40hedhMehAO2ljKdjALQ8l0w5Gf9gDc761BnFguZzlCwlA0vXdhbT9NNMlKqaKc/JM4lQzMQcajdeqngg/CUUt6IyDxZhaBOv1WqcNUxJt8EVPPY3r1E3rwgQpwmQL1Eb0hPpUGHxnhzC/B9cbGKylDh/XgfiNoieQ5KjrgwQYcfnXnKZpgql4RO4lXxmjZHUj58="
}
],
"cookies": [
{
"name": "ak_bmsc",
"value": "48DEF0C13393490FCEB2FDA5A4A47272D17497C42A7F0000DB37E559BE40FA5A~plKzlrqFeBqHoExIu4hYna8WskNf3a/28W7xdb5+d40hedhMehAO2ljKdjALQ8l0w5Gf9gDc761BnFguZzlCwlA0vXdhbT9NNMlKqaKc/JM4lQzMQcajdeqngg/CUUt6IyDxZhaBOv1WqcNUxJt8EVPPY3r1E3rwgQpwmQL1Eb0hPpUGHxnhzC/B9cbGKylDh/XgfiNoieQ5KjrgwQYcfnXnKZpgql4RO4lXxmjZHUj58=",
"expires": null,
"httpOnly": false,
"secure": false
}
]
},
"response": {
"status": 301,
"statusText": "Moved Permanently",
"httpVersion": "HTTP/1.1",
"headers": [
{
"name": "Location",
"value": "https://www.allstate.com/"
},
{
"name": "Date",
"value": "Mon, 16 Oct 2017 22:51:06 GMT"
},
{
"name": "Server",
"value": "AkamaiGHost"
},
],
"cookies": [],
"redirectURL": "https://www.allstate.com/",
"headersSize": 236,
"bodySize": 0,
"_transferSize": 236
}
}
我正在寻找一种无头镀铬的方法,它返回这部分:
"request": {
"method": "GET",
"url": "http://www.allstate.com/",
"httpVersion": "HTTP/1.1",
"headers": [
{
"name": "User-Agent",
"value": "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"
},
{
"name": "cookie",
"value": "ak_bmsc=48DEF0C13393490FCEB2FDA5A4A47272D17497C42A7F0000DB37E559BE40FA5A~plKzlrqFeBqHoExIu4hYna8WskNf3a/28W7xdb5+d40hedhMehAO2ljKdjALQ8l0w5Gf9gDc761BnFguZzlCwlA0vXdhbT9NNMlKqaKc/JM4lQzMQcajdeqngg/CUUt6IyDxZhaBOv1WqcNUxJt8EVPPY3r1E3rwgQpwmQL1Eb0hPpUGHxnhzC/B9cbGKylDh/XgfiNoieQ5KjrgwQYcfnXnKZpgql4RO4lXxmjZHUj58="
}
],
}
我尝试使用此方法https://chromedevtools.github.io/devtools-protocol/tot/Network/#event-requestWillBeSent,但它从不显示Cookie ...