Shell 命令 curl 和 wget 使用代理採集網頁的總結大全

來源:互聯網
上載者:User

Linux Shell 提供兩個非常實用的命令來爬取網頁,它們分別是 curl 和 wget

米撲代理,作為大資料分析研究的基礎服務,對其做了深入的研究和總結。

 

curl 和 wget 使用代理

curl 支援 http、https、socks4、socks5

wget 支援 http、https


Shell curl wget 樣本

#!/bin/bash## curl 支援 http、https、socks4、socks5# wget 支援 http、https## 米撲代理樣本:# https://proxy.mimvp.com/demo2.php## 米撲代理購買:# https://proxy.mimvp.com## mimvp.com# 2015-11-09#【米撲代理】:本樣本,在CentOS、Ubuntu、MacOS等伺服器上,均測試通過## http代理格式 http_proxy=http://IP:Port# https代理格式 https_proxy=http://IP:Port## proxy no auth# curl和wget,爬取http網頁{'http': 'http://120.77.176.179:8888'}curl -m 30 --retry 3 -x http://120.77.176.179:8888 http://proxy.mimvp.com/test_proxy2.php        # http_proxywget -T 30 --tries 3 -e "http_proxy=http://120.77.176.179:8888" http://proxy.mimvp.com/test_proxy2.php  # http_proxy# curl和wget,爬取https網頁(注意:添加參數,不經過SSL安全驗證){'https': 'http://46.105.214.133:3128'}curl -m 30 --retry 3 -x http://46.105.214.133:3128 -k https://proxy.mimvp.com/test_proxy2.php        # https_proxywget -T 30 --tries 3 -e "https_proxy=http://46.105.214.133:3128" --no-check-certificate https://proxy.mimvp.com/test_proxy2.php# https_proxy    # curl 支援socks# 其中,socks4和socks5兩種協議的代理,都可以同時爬取http和https網頁{'socks4': '101.255.17.145:1080'}curl -m 30 --retry 3 --socks4 101.255.17.145:1080 http://proxy.mimvp.com/test_proxy2.phpcurl -m 30 --retry 3 --socks4 101.255.17.145:1080 https://proxy.mimvp.com/test_proxy2.php    {'socks5': '82.164.233.227:45454'}curl -m 30 --retry 3 --socks5 82.164.233.227:45454 http://proxy.mimvp.com/test_proxy2.phpcurl -m 30 --retry 3 --socks5 82.164.233.227:45454 https://proxy.mimvp.com/test_proxy2.php# wget 不支援socks## proxy auth(代理需要使用者名稱和密碼驗證)# curl和wget,爬取http網頁curl -m 30 --retry 3 -x http://username:password@210.159.166.225:5718 http://proxy.mimvp.com/test_proxy2.php# httpcurl -m 30 --retry 3 -x http://username:password@210.159.166.225:5718 https://proxy.mimvp.com/test_proxy2.php# httpscurl -m 30 --retry 3 -U username:password -x http://210.159.166.225:5718 http://proxy.mimvp.com/test_proxy2.php# httpcurl -m 30 --retry 3 -U username:password -x http://210.159.166.225:5718 https://proxy.mimvp.com/test_proxy2.php# httpscurl -m 30 --retry 3 --proxy-user username:password -x http://210.159.166.225:5718 http://proxy.mimvp.com/test_proxy2.php# httpcurl -m 30 --retry 3 --proxy-user username:password -x http://210.159.166.225:5718 https://proxy.mimvp.com/test_proxy2.php# httpswget -T 30 --tries 3 -e "http_proxy=http://username:password@2.19.16.5:5718" http://proxy.mimvp.com/test_proxy2.phpwget -T 30 --tries 3 -e "https_proxy=http://username:password@2.19.16.5:5718" https://proxy.mimvp.com/test_proxy2.phpwget -T 30 --tries 3 --proxy-user=username --proxy-password=password -e "http_proxy=http://2.19.16.5:5718" http://proxy.mimvp.com/test_proxy2.phpwget -T 30 --tries 3 --proxy-user=username --proxy-password=password -e "https_proxy=http://2.19.16.5:5718" https://proxy.mimvp.com/test_proxy2.php# curl 支援sockscurl -m 30 --retry 3 -U username:password --socks5 21.59.126.22:57216 http://proxy.mimvp.com/test_proxy2.php# httpcurl -m 30 --retry 3 -U username:password --socks5 21.59.126.22:57216 https://proxy.mimvp.com/test_proxy2.php# httpscurl -m 30 --retry 3 --proxy-user username:password --socks5 21.59.126.22:57216 http://proxy.mimvp.com/test_proxy2.php# httpcurl -m 30 --retry 3 --proxy-user username:password --socks5 21.59.126.22:57216 https://proxy.mimvp.com/test_proxy2.php# https# wget 不支援socks



wget 設定檔設定代理

vim ~/.wgetrchttp_proxy=http://120.77.176.179:8888:8080https_proxy=http://12.7.17.17:8888:8080use_proxy = onwait = 30# 設定檔設定後,立即生效,直接執行wget爬取命令即可wget -T 30 --tries 3 http://proxy.mimvp.com/test_proxy2.phpwget -T 30 --tries 3 https://proxy.mimvp.com/test_proxy2.php


Shell 設定臨時局部代理

# proxy no authexport http_proxy=http://120.77.176.179:8888:8080export https_proxy=http://12.7.17.17:8888:8080# proxy auth(代理需要使用者名稱和密碼驗證)export http_proxy=http://username:password@120.77.176.179:8888:8080export https_proxy=http://username:password@12.7.17.17:8888:8080# 直接爬取網頁curl -m 30 --retry 3 http://proxy.mimvp.com/test_proxy2.php# http_proxycurl -m 30 --retry 3 https://proxy.mimvp.com/test_proxy2.php# https_proxywget -T 30 --tries 3 http://proxy.mimvp.com/test_proxy2.php# http_proxywget -T 30 --tries 3 https://proxy.mimvp.com/test_proxy2.php# https_proxy# 取消設定unset http_proxyunset https_proxy


Shell 設定系統全域代理

# 修改 /etc/profile,儲存並重啟伺服器sudo vim /etc/profile# 所有人有效或sudo vim ~/.bashrc# 所有人有效或vim ~/.bash_profile# 個人有效## 在檔案末尾,添加如下內容# proxy no authexport http_proxy=http://120.77.176.179:8888:8080export https_proxy=http://12.7.17.17:8888:8080# proxy auth(代理需要使用者名稱和密碼驗證)export http_proxy=http://username:password@120.77.176.179:8888:8080export https_proxy=http://username:password@12.7.17.17:8888:8080## 執行source命令,使設定檔生效(臨時生效)source /etc/profile或source ~/.bashrc或source ~/.bash_profile## 若需要機器永久生效,則需要重啟伺服器sudo reboot


米撲代理樣本

米撲代理,專註為企業提供國內大資料研究服務,技術團隊來自百度、小米、阿里、創新工場等,為國內企業提供大資料擷取、資料建模分析、結果匯出展示等服務。

米撲代理樣本,包含Python、Java、PHP、C#、Go、Perl、Ruby、Shell、NodeJS、PhantomJS、Groovy、Delphi、易語言等十多種程式設計語言或指令碼,通過大量的可運行執行個體,詳細講解了使用代理IP的正確方法,方便網頁爬取、資料擷取、自動化測試等領域。


米撲代理樣本官網 :

https://proxy.mimvp.com/demo2.php


相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.