37,744
社区成员




>>> import re
>>> s = '''<table>
<tr>
<td>序列号</td><td>DEIN3-39CD3-2093J3</td>
<td>日期</td><td>2013年1月22日</td>
<td>售价</td><td>392.70 元</td>
<td>说明</td><td>仅限5用户使用</td>
</tr>
</table>'''
>>> res = r'<td>(.*?)</td><td>(.*?)</td>'
>>> m = re.findall(res,s,re.S|re.M)
>>> m
[('\xd0\xf2\xc1\xd0\xba\xc5', 'DEIN3-39CD3-2093J3'), ('\xc8\xd5\xc6\xda', '2013\xc4\xea1\xd4\xc222\xc8\xd5'), ('\xca\xdb\xbc\xdb', '392.70 \xd4\xaa'), ('\xcb\xb5\xc3\xf7', '\xbd\xf6\xcf\xde5\xd3\xc3\xbb\xa7\xca\xb9\xd3\xc3')]
>>> for line in m:
print line[0],line[1]
序列号 DEIN3-39CD3-2093J3
日期 2013年1月22日
售价 392.70 元
说明 仅限5用户使用
>>>
lines = '''
<table>
<tr>
<td>序列号</td><td>DEIN3-39CD3-2093J3</td>
<td>日期</td><td>2013年1月22日</td>
<td>售价</td><td>392.70 元</td>
<td>说明</td><td>仅限5用户使用</td>
</tr>
</table>
'''.decode('gbk').encode('utf-8')
import re
m = re.findall(r'<td>(.*?)</td>', lines, re.I|re.M)
if m:
for x in m:
print x
#!/usr/bin/env python
lines = '''
<table>
<tr>
<td>序列号</td><td>DEIN3-39CD3-2093J3</td>
<td>日期</td><td>2013年1月22日</td>
<td>售价</td><td>392.70 元</td>
<td>说明</td><td>仅限5用户使用</td>
</tr>
</table>
'''
import re
m = re.findall(r'<td>(.*?)</td>', lines, re.I|re.M)
if m:
for x in m:
print x