我有一个网络爬虫抓取以下数据:
TESTDATA
DATA:DATA
Data £9500
Data £930
Data £500
Data £2250
Data £930
Data £500
Data £2250
DATATEST
DATA:DATA
Data £95001
Data £9302
Data £5003
Data £22504
Data £9305
Data £5006
Data £22507
运行:print full_end
返回:
[u'TESTDATA', 'DATA:DATA', 'Data £9500', 'Data £930', 'Data £500', 'Data £2250', 'Data £930', 'Data £500', 'Data £2250', '\r', DATATEST', 'DATA:DATA', 'Data £95001', 'Data £9302', 'Data £5003', 'Data £22504', 'Data £9305', 'Data £5006', 'Data £22507']
运行:print repr(full_end)
返回:
u"TESTDATA\nDATA:DATA\nData £9500\nData £930\nData £500\nData £2250\nData £930\nData £500\nData £2250\n\r\nDATATEST\nDATA:DATA\nData £95001\nData £9302\nData £5003\nData £22504\nData £9305\nData £5006\nData £22507"
运行:print repr('\r\n'.join(full_end).strip())
返回:
u"TESTDATA\r\nDATA:DATA\r\nData £9500\r\nData £930\r\nData £500\r\nData £2250\r\nData £930\r\nData £500\r\nData £2250\r\n\r\r\nDATATEST\r\nDATA:DATA\r\nData £95001\r\nData £9302\r\nData £5003\r\nData £22504\r\nData £9305\r\nData £5006\r\nData £22507"
图片:http: //i.imgur.com/Qe0TE5Y.png
使用以下脚本
with open('FULL_DATA.txt','r') as full_end_datafile:
full_end_datafile_read = full_end_datafile.read()
encoded_data = '\n'.join(full_end).encode("Latin-1")
if full_end_datafile_read == encoded_data:
encoded_data = ""
else:
with open('FULL_DATA.txt','w') as full_end_datafile:
full_end_datafile.write('\n'.join(full_end).encode("Latin-1"))
注意:在记事本中编辑文件会在每个数据集/组之间显示 1 行,在记事本 ++ 中它会在每个数据集/组之间显示 2 行
如果我将写入和读取选项更改为rb
,wb
我会得到以下信息:
它不识别数据是相同的,它重新保存文件
有人知道怎么修这个东西吗?
提前致谢 - Hyflex