huanghuahua
V2EX  ›  问与答

python 正则匹配中文问题。

  •  
  •   huanghuahua · Oct 30, 2015 · 1363 views
    This topic created in 3857 days ago, the information mentioned may be changed or developed.

    我扒下来的豆瓣登陆网页源码里有验证码信息,有一行代码是这样的:

    <span id="captcha_block" class="pl">请输入上图中的单词</span>

    我想要用正则匹配,里面的 请输入上图中的单词 这几个中文代码如下:
    pattern = re.compile(r'<span id="captcha_block" class="pl">(.*?)</span>',re.S)
    result = re.search(pattern,contents)
    print result

    ccontents 就是源码,但是运行结果是 none ,就是匹配失败了,请问了,要怎么样来匹配中文,以这个为例,在网上搜了很多,讲的都是编码, gtk utf-8 的没看懂,请大家帮助一下,谢谢。

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3046 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 08:37 · PVG 16:37 · LAX 01:37 · JFK 04:37
    ♥ Do have faith in what you're doing.