【发布时间】:2010-12-02 06:05:21
【问题描述】:
我一直在整理一份我们需要用新内容更新的页面列表(我们正在切换媒体格式)。在此过程中,我正在对正确包含新内容的页面进行编目。
这是我正在做的事情的总体思路:
- 遍历文件结构并获取文件列表
- 对于读取到缓冲区的每个文件,并使用正则表达式搜索匹配特定标签
- 如果匹配,再测试 2 个正则表达式匹配
- 将结果匹配(一个或另一个)写入数据库
在第 3 次正则表达式模式匹配之前一切正常,我得到以下信息:
'NoneType' object has no attribute 'group'
# only interested in embeded content
pattern = "(<embed .*?</embed>)"
# matches content pointing to our old root
pattern2 = 'data="(http://.*?/media/.*?")'
# matches content pointing to our new root
pattern3 = 'data="(http://.*?/content/.*?")'
matches = re.findall(pattern, filebuffer)
for match in matches:
if len(match) > 0:
urla = re.search(pattern2, match)
if urla.group(1) is not None:
print filename, urla.group(1)
urlb = re.search(pattern3, match)
if urlb.group(1) is not None:
print filename, urlb.group(1)
谢谢。
【问题讨论】: