所以基本上,我正在创建一个程序,我从Reddit抓取子Reddit的列表,并将它们存储在一个txt文件中。但是,我不知道如何计算重复项。因此,如果我运行它,并且文件中已经有一个名称,我如何将值“加1”?所以它可以是这样的: subone :1 subtwo :3 subthree: 2
以此类推。
这就是我所拥有的:
class Isduplicate:
def read(self):
f = open(r'C:\Users\jacka\OneDrive\Documents\outputs.txt', "r")
contents = f.read()
return contents
while counter < len(elem):
e = str(elem[counter].get_attribute("href"))
e = e.replace("https://www.reddit.com/r/", "")
e = e[:-1]
if e in Is.read():
text_file.write("duplicate found")
else:
text_file.write(e + "\n")
print(e)
counter = counter +2
任何一般性的建议也是值得感谢的!
https://stackoverflow.com/questions/51529507
复制相似问题