代理服务器

代理网址 http://www.xicidaili.com

urllib.request.ProxyHandler({"http":端口})

//代理操作

urllib.request.build_opener(代理名,urllib.request,HTTPHandler)

import urllib.request

//代理模块都request下
def use_proxy(url,duan):

//用函数对代理简单操作
file=urllib.request.ProxyHandler({"http":duan})
tom=urllib.request.build_opener(file,urllib.request.HTTPHandler)
urllib.request.install_opener(tom)
date=urllib.request.urlopen(url).read().decode("utf-8","ignore")

//把爬取值解码为utf-8格式
return date
url="http://www.baidu.com"
duan="119.28.194.66:8888"
wang=use_proxy(url,duan)
print(len(wang))

//操作完毕

原文地址:https://www.cnblogs.com/chunqing/p/9065569.html