我试图用 3 个小时来解决这个问题。请问你能告诉我有什么问题吗?这些是我的代码
import urllib
from jin import HtmlMigrate
from bs4 import BeautifulSoup
import logging
list2=[]
logging.basicConfig( format='%(levelname)s:%(message)s', level=logging.INFO)
current = 1
source =""
for v in range(13960581, 13960585):
list=[]
try:
fil = urllib.urlopen(source+str(v))
fill = fil.read()
soup = BeautifulSoup(fill)
k = soup.find("div", "post-taglist")
for i in k.findAll("a"):
list.append(i.string)
except AttributeError:
pass
if "python" in list:
try:
a = soup.find( "div", "post-text")
list2.append(a)
logging.info("%s question localized." % str(current))
except AttributeError:
pass
current +=1
mig = HtmlMigrate()
out = file("stackover.html", "w")
for i in list2:
mig.run(i, out)
out.close()
问题是我在控制台中为每个 logger.info 调用获得了重复的条目。我该如何解决这个问题?