python爬虫——设置多个ip代理

import urllib.requests
def proxy_user():
	proxy_list=[#自己去网上搜免费的或者是付费的
		{"http":"183.154.55.162:9999"},
		{"http":"117.88.177.141:3000"},
		{"http":"222.189.191.165:9999"},
		{"http":"121.237.148.59:3000"}]
	for proxy in proxy_list:
		#利用遍历出来的ip创建处理器
		proxy_handler = urllib.request.ProxyHandler(proxy)
		#创建opener
		opener = urllib.request.build_opener(proxy_handler)
		  try:
           opener.open("http://www.baidu.com")
           print("haha")
       except Exception as e:
           print(e)

proxy_user()
发布了14 篇原创文章 · 获赞 0 · 访问量 102

猜你喜欢

转载自blog.csdn.net/weixin_45051787/article/details/104300002