學(xué)習(xí)網(wǎng)絡(luò)爬蟲難免遇到使用代理的情況,下面介紹一下如何使用requests設(shè)置代理:
如果需要使用代理,你可以通過為任意請求方法提供 proxies 參數(shù)來配置單個請求:
1
2
3
|
import requests proxies = { "http" : "http://10.10.1.10:3128" , "https" : "http://10.10.1.10:1080" , } requests.get( "http://example.org" , proxies = proxies) |
這里的可以通過ip測試網(wǎng)站進(jìn)行驗(yàn)證是否成功使用了代理 http://ip.chinaz.com/(查看你訪問后的網(wǎng)站的您的IP是多少來判斷)
有關(guān)requests的出現(xiàn)亂碼問題的解決可以查看
python中requests爬去網(wǎng)頁內(nèi)容出現(xiàn)亂碼問題解決方法介紹
有關(guān)requests的使用cookies問題的解決可以查看
python編程之requests在網(wǎng)絡(luò)請求中添加cookies參數(shù)方法詳解
以上就是本文關(guān)于python中requests使用代理proxies方法介紹的全部內(nèi)容,希望對大家有所幫助。
原文鏈接:http://blog.csdn.net/winterto1990/article/details/51220307