码迷,mamicode.com
首页 > 编程语言 > 详细

python 爬虫 代理

时间:2017-11-23 08:35:32      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:import   open   this   UI   port   rand   data   www.   hand   

import random
import urllib.request
ippools=[
"39.104.50.71:8080",
"39.104.50.160:8080",
"39.104.14.202:8080",
"39.104.50.137:8080",
"39.104.50.29:8080"
]
def ip(ippools):
thisip=random.choice(ippools)
print(thisip)
proxy=urllib.request.ProxyHandler({"http": thisip})
opener=urllib.request.build_opener(proxy,urllib.request.HTTPHandler)
urllib.request.install_opener(opener)

for i in range(0,5):
try:
ip(ippools)
url="http://www.baidu.com"
data=urllib.request.urlopen(url).read()
print(len(data.decode()))
except Exception as err:
print(err)

python 爬虫 代理

标签:import   open   this   UI   port   rand   data   www.   hand   

原文地址:http://www.cnblogs.com/xiesongyou/p/7881628.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!