Python爬虫——代理服务器进行信息的爬取

版权声明:未经同意窃取和转载我的内容,如果涉及到权益问题,后果自负! https://blog.csdn.net/weixin_41605937/article/details/84332242
利用代理服务器进行信息的爬取以防止自己的IP的被服务器封
def function1(url,IP):#url  IP
    """代理服务器进行信息的爬取以防止自己的IP的被服务器封"""
    proxy=urllib.request.ProxyHandler({"http":IP})#http:IP:端口
    opener=urllib.request.build_opener(proxy,urllib.request.HTTPHandler)
    urllib.request.install_opener(opener)#添加全局
    data=urllib.request.urlopen(url).read().decode("utf-8","ignore")
    print(len(data))
    print("爬虫代理服务器结束")
    return

if __name__ == '__main__':
    url="http://www.baidu.com"
    IP="110.179.64.194:8123"#这是代理服务器的问题需要不断的进行调整免费的IP地址
    function1(url,IP)

免费的代理的IP地址我已经附上链接自己去改动就好;http://www.xicidaili.com/

猜你喜欢

转载自blog.csdn.net/weixin_41605937/article/details/84332242
今日推荐