requests請求報錯:Invalid header name b:authority

第一次遇見這種問題,雖然很小已解決,但還是要記錄一下。

在爬取http://www.questmobile.com.cn/這個網站時,遇到圖片無法加載的問題,其中顯示如標題這種錯誤,

其他數據都可以抓取下來,但唯獨圖片不可加載。

這種問題就出現在請求頭上,如下:

self.headers = {
            ':authority': 'ws.questmobile.cn',
            ':method': 'GET',
            ':path': '/website/article/images/72/21.JPG',
            'scheme': 'https',
            'accept': 'image/webp,image/apng,image/*,*/*;q=0.8',
            'accept-encoding': 'gzip, deflate, br',
            'accept-language': 'zh-CN,zh;q=0.9',
            'referer': 'http://www.questmobile.com.cn/research/report-new/72/',
            'sec-fetch-mode': 'no-cors',
            'sec-fetch-site': 'cross-site',
            'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3941.4 Safari/537.36'
        }

只要將請求頭中key值之前帶有的“:”去掉,然後去請求就成功了,其它按正常思路走就可以了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章