马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import urllib.request
import os
import re
import time
def url_open(url):
a =urllib.request.Request(url)
a.add_header('User-Agent','Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.26 Safari/537.36 Core/1.63.6823.400 QQBrowser/10.3.3117.400')
req = urllib.request.urlopen(a)
html = req.read().decode('utf-8')
return html
def zhuyao(html):
p = r'(?:(?:[01]\d\d|2[0-4]\d|25[0-5]|[0-9]\d|[0-9])\.){3}(?:[01]\d\d|2[0-4]\d|25[0-5]|[0-9]\d|[0-9])'
ipopen = re.findall(p,html)
with open('文件ip代理','a') as f:
for each in ipopen:
each = each+'\n'
f.write(each)
if __name__=='__main__':
cishu = 0
os.mkdir('ip代理')
os.chdir('ip代理')
for each in range(10):
cishu+=1
url = 'https://www.kuaidaili.com/free/intr/'+str(cishu)+'/'
zhuyao(url_open(url))
time.sleep(5)
|