但是最近在网络爬虫的过程中,发现一个让人头大的问题。Python3使用requests 抓取信息时遇到304状态码。。。这有些让我摸不着头脑,从返回的状态码来看,应该抓取的内容没有抓取到,查询资料得知是由于请求的header中包含以下两个键值对,那么每次请求将这两个值赋值为空解决了问题:If-None-Natch,If-Modified-Since
headers = {
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"accept-encoding": "gzip, deflate, br",
"accept-language": "zh-CN,zh;q=0.9",
"cache-control": "max-age=0",
"cookie": "__yjs_duid=1_06d53fe303b699751bfabe6b9489aa101667713733022; Hm_lvt_c59f2e992a863c2744e1ba985abaea6c=1667713735; zkhanecookieclassrecord=%2C68%2C54%2C; Hm_lpvt_c59f2e992a863c2744e1ba985abaea6c=1667713739",
"if-modified-since": "Fri, 04 Nov 2022 16:27:59 GMT",
"referer": "https://pic.netbian.com/shoujibizhi/",
"sec-ch-ua": "\";Not A Brand\";v=\"99\", \"Chromium\";v=\"94\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Windows\"",
"sec-fetch-dest": "document",
"sec-fetch-mode": "navigate",
"sec-fetch-site": "same-origin",
"sec-fetch-user": "?1",
"upgrade-insecure-requests": "1",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36 Core/1.94.178.400 QQBrowser/11.2.5170.400",
'If-None-Natch':'',
'If-Modified-Since':''
}