爬取IP

import urllib.request
import re def url_open(url):
req = urllib.request.Request(url,headers={'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.75 Safari/537.36 LBBROWSER'})
response =urllib.request.urlopen(url)
html = response.read().decode('utf-8')
return html def get_img(html):
p = r'(?:(?:[0-1]?\d?\d|2[0-4]\d|25[0-5])\.){3}(?:[0-1]?\d?\d|2[0-4]\d|25[0-5])'
iplist =re.findall(p,html) for each in iplist:
print(each)
'''
filename = each.split('/')[-1]
urllib.request.urlretrieve(each,filename,None)''' if __name__ == '__main__':
url = 'http://www.proxy360.cn/default.aspx'
get_img(url_open(url))
上一篇:SpringBoot掌握的差不多了,就剩下一个Actuator没搞定了,本文详细来介绍!!!


下一篇:使用PHP扩展Xhprof分析项目性能实践