python3 如何使用ip、爬虫

使用urllib.request、random模块,不说了贴代码

url="*";

iplist=['70.254.226.206:8080'];
proxy_support=urllib.request.ProxyHandler({"http":random.choice(iplist)})
opener=urllib.request.build_opener(proxy_support)
opener.addheaders=[('User-Agent','Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36')]
urllib.request.install_opener(opener)
response=urllib.request.urlopen(url)
html=response.read().decode("utf-8")
print(html)

上一篇:Asp.net Core认证和授权:Cookie认证


下一篇:JavaScript和prototype