爬虫防屏蔽 代理服务器

import urllib.request

def use_proxy(url,proxy_addr):

 proxy=urllib.request.ProxyHandler({"http":proxy_addr})

 opener = urllib.request.build_opener(proxy,urllib.request.HTTPHandler)

 urllib.request.install_opener(opener)

 data = urllib.request.urlopen(url).read().decode("utf-8","ingnore")

 return data

proxy_addr = "ip:端口"

url = "要爬的网址"

data = use_proxy(url,proxy_addr)

print(len(data))

你可能感兴趣的:(数据分析)