Axios使用總結


一. 下圖查看源碼獲得,表示axios網絡請求后返回數據類型

 

 1. AxiosResponse

  經測試data表示獲取的數據

 

二. 設置axios的請求配置

在創建axios時進行設置

 

三. 設置請求頭(headers)在http的源碼字段

 

 

四. 使用axios爬蟲遇到問題

錯誤1:訪問不安全的https網絡

Error [ERR_TLS_CERT_ALTNAME_INVALID]: Hostname/IP does not match certificate's altnames: Host: www.100sht.info. is not in the cert's altnames: DNS:98ska.space, DNS:www.98ska.space

 

錯誤2:重定向次數超過上限

Error: Max redirects exceeded.

 

解決:

const instance = axios.create({
  // 設置cookie,解決報錯重定向超過最大值
  // 可以先瀏覽器訪問那個要爬蟲的網站,然后把cookie從headers從復制出來
  headers: {
    'cookie': 'xxxxxxxxx'
  },
  // 為了忽略https證書錯誤
  httpsAgent: new https.Agent({
    rejectUnauthorized: false
  }),
});

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM