1
jookr 2014 年 12 月 16 日
大神 能否指点一下,我昨天刚入门
正则截取内容不会 下面这个例子 我需要截取"啊啊啊"这个内容出来怎么获取不到呢 import re html = 'www啊啊啊,呵呵,哈哈,嘿嘿' counts = re.findall(r'"www(.*),呵呵,哈哈,嘿嘿', html) print counts[1] raw_input() |
2
realityone 2014 年 12 月 16 日 |
3
jookr 2014 年 12 月 16 日
中文的逗号匹配结尾会提示错误怎么办
|
4
jookr 2014 年 12 月 16 日
@realityone 谢谢
但是你的代码会获取整个www后面的内容,不能只截取出"啊啊啊" import re html = 'www啊啊啊,呵呵,哈哈,嘿嘿' #counts = re.findall(r'"www(.*),呵呵,哈哈,嘿嘿', html) counts = re.findall(r'www(.*)', html) get_content = counts[0] print get_content.decode('utf-8').encode('cp936') |
5
jookr 2014 年 12 月 16 日
自己解决了
# -*- coding: utf-8 -*- import re html = 'www啊啊啊,呵呵,哈哈,嘿嘿' #counts = re.findall(r'"www(.*),呵呵,哈哈,嘿嘿', html) counts = re.findall(r'www(.*?),(.*?),(.*?),', html) get_content = counts[0] #print get_content for i in get_content: print i.decode('utf-8').encode('cp936') |
7
Bitex 2014 年 12 月 16 日
|
8
0x5e 2014 年 12 月 16 日
@realityone 哟西,好巧:-)
|
9
R4rvZ6agNVWr56V0 2014 年 12 月 17 日
fun
|
10
4everLoveU 2014 年 12 月 19 日
好东西,不错,支持一下!
|
11
mingyun 2015 年 1 月 11 日
star
|