python爬虫——IP代理

首先我们要买代理IP,最好是1分钟1换的 

import urllib.request as ur

#这里就是买的IP,反馈的地址
proxy_address = ur.urlopen('http://api.ip.data5u.com/dynamic/get.html?order=d314e5e5e19b0dfd19762f98308114ba&sep=4').read().decode('utf-8').strip()
print(proxy_address)

# 创建proxy_handler
proxy_handler = ur.ProxyHandler(
    {
        'http':proxy_address
    }
)
# 新建opener对象
proxy_opener = ur.build_opener(proxy_handler)

request = ur.Request(url='https://edu.csdn.net/')
reponse = proxy_opener.open(request).read()
print(reponse)

 

你可能感兴趣的:(爬虫,python)