Python代码
- #!/usr/bin/python
- #-*-coding:gb2312-*-
- #说明:获取配置文件中某个项的所有值,并根据re返回结果
- import re,ConfigParser
- def getcfg(html,cfgpath,cfgname):
- config = ConfigParser.ConfigParser();
- config.read(cfgpath);
- rex = config.options(cfgname);
- relist = [];
- for x in rex:
- relist.append(config.get(cfgname,x))
- for sqln,regx in zip(rex,relist):
- sqln = re.findall(regx,html,re.DOTALL)
- return sqln
- html = urllib2.urlopen('http://blog.591by.com').read();
- getcfg(html,'e:\\xorg.cfg','collet');
