ip

喜你入骨 提交于 2019-12-03 04:31:44
#代理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()#关一下
"""
#同上一样
"""
#代理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"
     ]
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)
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)
"""
"""
#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)
"""
 
       
   
 
 
 
 
 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!