V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
muxi
V2EX  ›  Python

求助,一个诡异的正则表达式查找问题

  •  
  •   muxi ·
    cuimuxi · 2010-11-19 17:08:52 +08:00 · 4359 次点击
    这是一个创建于 4878 天前的主题,其中的信息可能已经有所发展或是发生改变。
    def get_city_list(self, site):
    city = re.findall(site['city_tag'], self.root, re.S)
    if not city:
    return false
    else:
    return city

    这个怎么都匹配不到内容
    =========================================


    def get_city_list(self, site):
    a = '<division>(.*?)</division>'
    city = re.findall(a, self.root, re.S)

    我把上面site['city_tag']内容拿出来,赋值给a

    就能匹配到了

    ====================


    说明:site['city_tag'] 是从数据库中取出来的,数据库编码为UTF8
    site['city_tag']的内容就是下面定义a的内容


    这是为什么呢?编码问题?
    type(site['city_tag'])显示是unicode
    type(self.root) 也显示的是unicode

    为啥就不能匹配到呢?这是为什么呢?
    折腾了快一下午了,实在想不明白,请各位高手帮助
    1 条回复    1970-01-01 08:00:00 +08:00
    keakon
        1
    keakon  
       2010-11-19 17:24:02 +08:00
    用logging把site['city_tag']和self.root记录下来,或者直接debug

    然后手动运行一遍

    代码本身没错,我想应该是数据的问题

    话说为什么存储要用XML格式,使用起来非常麻烦
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   944 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 20:57 · PVG 04:57 · LAX 13:57 · JFK 16:57
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.