from pprint import pp from pathlib import Path from urllib import request import re urlroot = 'https://www.w3.org/Protocols/rfc2616' src = Path('src') root = src.joinpath('error') with root.joinpath('root.html').open('r') as root_file: root_html = root_file.read() with root.joinpath('root.css').open('r') as root_file: root_css = root_file.read() error = Path('dist_error') error.mkdir(exist_ok=True) for x in error.rglob('*'): if x.is_file() or x.is_symlink(): x.unlink() req = request.Request( f'{urlroot}/rfc2616-sec10.html', method='GET') with request.urlopen(req) as res: raw = res.read().decode('utf-8') codes = (re.finditer(r"(?s)
(.*?)
', raw)) nginx_head = '' nginx_body = '' for item in codes: sec, code, title, desc = item.groups() if int(code) < 400 or int(code) >= 600: continue desc = re.sub(r"(