我一直在列出需要用新内容更新的页面列表(我们正在切换媒体格式)。在这个过程中,我正在对正确包含新内容的页面进行编目。Python正则表达式“对象没有任何属性”
下面是我在做什么的总体思路:
- 迭代通过的文件结构,并得到使用正则表达式搜索文件
- 对于读取到缓冲区中的每个文件,列表,匹配特定标签
- 如果匹配,测试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)
谢谢。
啊。谢谢。我在代码中使用了选项卡,该代码由本网站的格式引擎重新格式化/重新解释。 “url不是无固定它” – ives 2009-09-29 17:10:04