1奸攻、302問題
- 場景:Mac上直接使用curl登錄網(wǎng)頁,like
curl https://我要到的網(wǎng)頁.com
- 返回錯誤信息:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved <a href="你需要轉(zhuǎn)到這個地址哦">here</a>.</p>
</body></html>
- 解決方案:
curl帶上-L即可
curl -L https://我要到的網(wǎng)頁.com
2呼伸、登錄問題
- 場景:Mac上直接使用curl登錄需要登錄賬戶的網(wǎng)頁身冀,like
curl https://我要到的需要登錄的網(wǎng)頁.com
- 返回錯誤信息:
Error: You must enable cookies on your web browser.
-
解決方案:
是的,你需要cookie
解決方案限定場景:- 使用Chrome等瀏覽器能登錄
- 能下載Chrome插件(FQ)
- Mac機(jī)(還沒試過Win蜂大,有試過的同學(xué)可以貼下是否可行)
解決步驟:
- 下載闽铐、安裝EditThisCookie插件蝶怔、導(dǎo)出Cookie為網(wǎng)景格式
下載EditThisCookie
設(shè)置為網(wǎng)景cookie格式
image.png -
登錄需要curl的頁面奶浦,將Cookie復(fù)制出來
image.png - vi或者vim或者nano或者sublimetext之類的,把cookie保存為文件
比如保存為this.cookie - 開心地curl通地址
curl -L(或許可以不加) -b cookie位置 網(wǎng)頁 如:curl -L -b ~/this.cookie https://終于能進(jìn)來啦.com
參考文章
https://www.quyu.net/info/1321.html 我要是能早點搜到它就好了.jpg
https://stackoverflow.com/questions/20905210/curl-302-redirect-not-working-command-line stackflow302問題
https://www.ruanyifeng.com/blog/2011/09/curl.html 一峰老師指南
https://curl.haxx.se/docs/http-cookies.html Curl官方的Cookies格式文檔