forked from zhangyingcc/spider_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHtmlMaker.py
More file actions
53 lines (47 loc) · 1.67 KB
/
HtmlMaker.py
File metadata and controls
53 lines (47 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/local/python275/bin/python2.7
# -*- coding: utf-8 -*-
'''
#=============================================================================
# FileName: main.py
# Desc:
# Author: linjay
# Email: linjayzhang326@gmail.com
# HomePage: https://github.com/Linjay
# Version: 0.0.2
# LastChange: 2013-8-13 17:12:36
# History:
#=============================================================================
'''
import redis
import time
class HtmlMaker():
def __init__(self, ip, port, path):
self.REDIS_IP = ip
self.REDIS_PORT = port
self.OUTPUT_PATH = path
def makeHtml(self):
f = open(self.OUTPUT_PATH,'w')
#file write only, create new file if it not exist
print>>f, """<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome to spider!</title>
<style>
body {
width: 35em;
margin: 0 auto;
}
a:visited { color: red; }
</style>
</head>
<body>""" #The HTML Code
rs = redis.Redis(host=self.REDIS_IP, port=self.REDIS_PORT)
#print rs.get("test")##just for test
ret = rs.smembers("urls")
for item in ret:
print>>f, item
print>>f, "<br/>"
print>>f, "<br/><br/>Update at:" +time.ctime()+ "<br/>"
print >> f, """</body></html>"""
f.close()