from urllib import request
from bs4 import BeautifulSoup
url = 'http://www.wineyun.com/'
rsp = request.urlopen(url)
content = rsp.read()
soup = BeautifulSoup(content, 'lxml')
content = soup.prettify()
title = soup.title
keywords = soup.find(attrs={"name":"keywords"})['content']
description = soup.find(attrs={"name":"description"})['content']
#print(title)
#print(keywords)
#print(description)
f = open('test.html','w')
message = """
<html>
<head>
%s
<meta name="keywords" content="%s">
<meta name="description" content="%s">
</head>
<body>
<p>首页网址:%s</p>
</body>
</html>"""%(title,keywords,description,url)
f.write(message)
f.close()
生成页面处可自行添加其他css,js进行完善