Python--网页更新监控工具
来源:互联网 发布:数据图表设计案例 编辑:程序博客网 时间:2024/05/16 17:35
Python--网页更新监控工具
(2012-08-04 17:29:05)转载▼
标签:
网页监控更新
python
it
分类:程序人生一、工作原理
表达式来进行过滤,发现效果和效率都不错。
差异结果。本工具的测试环境是:win7+python2.7.3,读者可以自行写个win系统的批处理脚本,定时调用此工具。第一次运行时候是没有结果输出的,因为第一次只是执行下载网页,还有比对的样本。还有就是,如果发现网页有更新,需要及时更新上一次的比对文件(txt格式文本)。
二、代码文件结构
1)downloadHtml
2)getEncoding
3)Html2Text
4)differFile
5)monitorHtml
三、测试截图
1)网页没有更新
2)网页有更新
留意有下划线部分内容,这就是网页内容有差异的部分。
四、主要代码
-----------downloadHtml-----------------------------
import urllib
import urllib2
import getEncoding
import sys
def downloadHtml(websize, savefile):
'''
this methodis used download html,but if html contain chinese charateres
should notuse this method
'''
#At firstcheck the encoding of html
encoding =getEncoding.quick_getHtmlEncoding(websize)
content =urllib2.urlopen(websize).read()
type =sys.getfilesystemencoding()
s =content.decode(encoding).encode(type)
file =open(savefile, 'wb')
file.write(s)
file.close()
留意有下划线部分内容,这就是网页内容有差异的部分。
四、主要代码
-----------downloadHtml-----------------------------
import urllib
import urllib2
import getEncoding
import sys
def downloadHtml(websize, savefile):
import difflib
def isDiff(srcfile, tarfile):
def getDetails(srcfile, tarfile, flag = 'all'):
--------monitorHtml-------------------------
import downloadHtml
import differFile
import Html2Text
import os.path
def isExists(saveFile):
def monitorHtml(websize, savehtml, savetxt, originaltxt):