#代理ip的构建
import urllib.request
ip="110.85.155.236:35127"
proxy=urllib.request.ProxyHandler({"http":ip})
#print(proxy)
opener=urllib.request.build_opener(proxy,urllib.request.HTTPHandler)
urllib.request.install_opener(opener)
url="Https://www.baidu.com"
data=urllib.request.urlopen(url).read().decode("utf-8","ingore")
print(len(data))
fh=open("C:\\Users\\何\\Desktop\\cold\\ip_baidu.html","w")
fh.write(data)
fh.close()#关一下
import urllib.request
ip="110.85.155.236:35127"
proxy=urllib.request.ProxyHandler({"http":ip})
#print(proxy)
opener=urllib.request.build_opener(proxy,urllib.request.HTTPHandler)
urllib.request.install_opener(opener)
url="Https://www.baidu.com"
data=urllib.request.urlopen(url).read().decode("utf-8","ingore")
print(len(data))
fh=open("C:\\Users\\何\\Desktop\\cold\\ip_baidu.html","w")
fh.write(data)
fh.close()#关一下
"""
#同上一样
"""
#代理ip的构建
import urllib.request
ip="110.85.155.236:35127"
proxy=urllib.request.ProxyHandler({"http":ip})
#print(proxy)
opener=urllib.request.build_opener(proxy,urllib.request.HTTPHandler)
urllib.request.install_opener(opener)
url="Https://www.baidu.com"
data1=urllib.request.urlopen(url).read()
data=data1.decode("utf-8","ingore")
print(len(data))
fh=open("C:\\Users\\何\\Desktop\\cold\\ip_baidu.html","wb")#wb二进制的方式
fh.write(data1)
fh.close()#关一下
"""
#同上一样
"""
#代理ip的构建
import urllib.request
ip="110.85.155.236:35127"
proxy=urllib.request.ProxyHandler({"http":ip})
#print(proxy)
opener=urllib.request.build_opener(proxy,urllib.request.HTTPHandler)
urllib.request.install_opener(opener)
url="Https://www.baidu.com"
data1=urllib.request.urlopen(url).read()
data=data1.decode("utf-8","ingore")
print(len(data))
fh=open("C:\\Users\\何\\Desktop\\cold\\ip_baidu.html","wb")#wb二进制的方式
fh.write(data1)
fh.close()#关一下
"""
"""
#ip代理池构建第一种方案(适合于IP稳定)
import random
import urllib.request
ippools=[
"110.85.155.236:35127"
"115.221.112.217:32323"
"210.47.167.234"
"61.238.68.187"
" 171.15.192.124"
]
#ip代理池构建第一种方案(适合于IP稳定)
import random
import urllib.request
ippools=[
"110.85.155.236:35127"
"115.221.112.217:32323"
"210.47.167.234"
"61.238.68.187"
" 171.15.192.124"
]
def ip(ippools):
thisip=random.choice(ippools)
print(thisip)
proxy=urllib.request.ProxyHandler({"http":ip})
opener=urllib.request.build_opener(proxy,urllib.request.HTTPHandler)
urllib.request.install_opener(opener)
thisip=random.choice(ippools)
print(thisip)
proxy=urllib.request.ProxyHandler({"http":ip})
opener=urllib.request.build_opener(proxy,urllib.request.HTTPHandler)
urllib.request.install_opener(opener)
for i in range(0,3):#循环
try:#异常处理
ip(ippools)#调用IP
url="Https://www.baidu.com"
data1=urllib.request.urlopen(url).read()
data=data1.decode("utf-8","ingore")
print(len(data))
fh=open("C:\\Users\\何\\Desktop\\cold\\ip_baidu_"+str(i)+".html","wb")#wb二进制的方式
fh.write(data1)
fh.close()#关一下
try:#异常处理
ip(ippools)#调用IP
url="Https://www.baidu.com"
data1=urllib.request.urlopen(url).read()
data=data1.decode("utf-8","ingore")
print(len(data))
fh=open("C:\\Users\\何\\Desktop\\cold\\ip_baidu_"+str(i)+".html","wb")#wb二进制的方式
fh.write(data1)
fh.close()#关一下
except Exception as err:#异常处理
print(err)
"""
"""
#ip代理池构建第一种方案(适合于IP稳定)同上,IP是thisip
import random
import urllib.request
ippools=[
"110.85.155.236:35127"
"115.221.112.217:32323"
"210.47.167.234"
"61.238.68.187"
" 171.15.192.124"
]
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,3):#循环
try:#异常处理
ip(ippools)#调用IP
url="Https://www.baidu.com"
data1=urllib.request.urlopen(url).read()
data=data1.decode("utf-8","ingore")
print(len(data))
fh=open("C:\\Users\\何\\Desktop\\cold\\ip_baidu_"+str(i)+".html","wb")#wb二进制的方式
fh.write(data1)
fh.close()#关一下
except Exception as err:#异常处理
print(err)
"""
print(err)
"""
"""
#ip代理池构建第一种方案(适合于IP稳定)同上,IP是thisip
import random
import urllib.request
ippools=[
"110.85.155.236:35127"
"115.221.112.217:32323"
"210.47.167.234"
"61.238.68.187"
" 171.15.192.124"
]
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,3):#循环
try:#异常处理
ip(ippools)#调用IP
url="Https://www.baidu.com"
data1=urllib.request.urlopen(url).read()
data=data1.decode("utf-8","ingore")
print(len(data))
fh=open("C:\\Users\\何\\Desktop\\cold\\ip_baidu_"+str(i)+".html","wb")#wb二进制的方式
fh.write(data1)
fh.close()#关一下
except Exception as err:#异常处理
print(err)
"""