1
c 2014-11-14 11:54:00 +08:00 1
re.findall('<Data>([^<]+)</Data>', s)
|
2
Kai MOD 移动到 /go/python
|
3
ChanneW 2014-11-14 12:43:25 +08:00
def tsplit(string, delimiters):
"""Behaves str.split but supports multiple delimiters.""" delimiters = tuple(delimiters) stack = [string,] for delimiter in delimiters: for i, substring in enumerate(stack): substack = substring.split(delimiter) stack.pop(i) for j, _substring in enumerate(substack): stack.insert(i+j, _substring) return stack s ="<Data>1=1&2=2</Data><Data>abc</Data><Data>nihao</Data>" tsplit(s, (',', '<Data>', '</Data>')) |
4
uJohnny 2014-11-14 15:45:15 +08:00
如果只是标签里的数据, 用lxml吧.
不想用的话, 就参考下这个: http://bit.ly/1qHjIeV |
5
fortunezhang OP @Kai 不知道怎么移动了。下次注意。thx
|
6
irosyking 2014-11-15 00:09:55 +08:00
正则表达式为 (?<=<data>)(.*?)(?=<\/data>)
import re m=re.findall(r'(?<=<data>)(.*?)(?=<\/data>)','<Data>1=1&2=2</Data><Data>abc</Data><Data>nihao</Data>',re.I|re.M) print m |