Python网络爬虫案例实战:静态网页爬取:代理访问

Python网络爬虫案例实战:静态网页爬取:代理访问

采集时为避免被封IP,经常会使用代理。Requests也有相应的proxies属性。例如:

import requests
proxies = {
    
    
    "http": "http://10.10.1.10:3128",
    "https": "http://10.10.1.10:1080",
}
requests.get("http://www.zhidaow.com", proxies = proxies)

如果代理需要账户和密码,则需如下这样:

proxies = {
    
    
    "http":"http://user:[email protected]:3128/",
}

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/andyyah/article/details/141099185