获取代理IP地址
import urllib.request
import re
def open_url(url):
req = urllib.request.Request(url)
req.add_header('User-Agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36')
page = urllib.request.urlopen(req)
html = page.read().decode('utf-8')
return html
def get_img(html):
# 第一个正则已经不行了
# p = r'(([0-1]{0,1}\d{0,1}\d|2[0-4]\d|25[0-5])\.){3}([0-1]{0,1}\d{0,1}\d|2[0-4]\d|25[0-5])'
# p = r'\d{0,3}\.\d{0,3}\.\d{0,3}\.\d{0,3}'
p = r'(?:(?:[0-1]{0,1}\d{0,1}\d|2[0-4]\d|25[0-5])\.){3}(?:[0-1]{0,1}\d{0,1}\d|2[0-4]\d|25[0-5])'
imglist = re.findall(p, html)
for each in imglist:
print(each)
if __name__ == '__main__':
# 代理地址改一下,书上的地址http://cn-proxy.com已经挂了
url = "http://www.data5u.com/"
get_img(open_url(url))