- 论坛徽章:
- 0
|
先说明目的:
打开下面的文件匹配html内容;找到则打印出来,找不到则返回"无"
我的文件内容如下:
a.txt(按行存储)
邬静娜
邬敏
郇公弟
郜彦伟
鄢闻余
奚春山
闫立良
闫婧宇
宓家峰
璩静
>>>myfile = open("a.txt")
>>>myfile.seek(0)
>>>str = myfile.read()
>>>a_file = str.decode("gb2312","ignore").encode("utf-8")
>>>for line in a_file.split('\n'):
... if re.search(line,html):
print line
else:
print "无"
>>> myfile.close() |
因为之前的html已经转换成了utf-8的编码,所以打开的文件a.txt也要转换,但转换之后,内容中有些错误有些丢失.不知道该怎么办了,还请高人指点.谢谢 |
|