1 回答
![?](http://img1.sycdn.imooc.com/54584cb50001e5b302200220-100-100.jpg)
TA贡献1851条经验 获得超5个赞
while True:
import time
import re
#input file
fin = open("ebay2.csv", "rt")
#output file to write the result to
fout = open("out.txt", "wt")
#for each line in the input file
for line in fin:
#read replace the string and write to output file
fout.write(line.replace('https://www.ebay.co.uk/sch/', 'https://').replace('itm', '/itm/').replace('https:www.ebay','https://www.ebay'))
with open('out.txt') as f:
regex = r"\d{12}"
subst = "/\\g<0>"
for l in f:
result = re.sub(regex, subst, l, 0, re.MULTILINE)
if result:
print(result)
fin.close()
fout.close()
time.sleep(1)
我最终想出了这个。这有点笨拙,但完成工作的速度足够快。
添加回答
举报