re正则匹配中文字符
re 匹配中文字符规则
re.compile(u"[\u4e00-\u9fa5]+")
下图是我爬取jd手表的一条数据 在该字典中的title键所对应的值value是我获取的整个em标签 因为我要获取整个em标签的中文内容
得到的title包括了标签本身 所以不满足我的需求
所以需要从title中只提取中文内容
watch_dic = {'category': '国内品牌',
'category_url': 'http://search.jd.com/Search?keyword=%E5%9B%BD%E8%A1%A8&enc=utf-8&suggest=1.def.0.T06&wq=guobiao&pvid=9m9nobvi.jilzz5#keyword=%E5%9B%BD%E8%A1%A8&enc=utf-8&qrst=1&rt=1&stop=1&vt=2&suggest=1.def.0.T06&wq=guobiao&wtype=1&click=1',
'detail_url': '//item.jd.com/100001920357.html',
'price': '1230.00',
'seller': '罗西尼腕表京东自营旗舰店',
'sub_category': '罗西尼',
'sub_category_url': 'https://search.jd.com/Search?keyword=%E7%BD%97%E8%A5%BF%E5%B0%BC&enc=utf-8',
'title': ['<em><font class="skcolor_ljg">罗西尼</font>(ROSSINI)手表 '
'雅尊商务系列黑盘钢带进口机芯机械表夜光男士腕表带日历男表618865W04C</em>']}
所以使用正则来完成
import re
title = watch_dic['title'][0]
res = re.find(u"[\u4e00-\u9fa5]+", title)
print('res=',res)
# 结果
res = ['罗西尼','手表','雅尊商务系列黑盘钢带进口机芯机械表夜光男士腕表带日历男表']