[英]Why are only the first and last items of my list being written to file?
我已經寫了我的第一個網絡爬蟲,現在正嘗試將數據寫入excel文件。
這是我程序的相關部分:
with xlsxwriter.Workbook('test 2.xlsx') as workbook:
worksheet = workbook.add_worksheet("Doctissimo's diabetes sub-forum")
row = 0
col = 0
for time, handle, post, URL in list(zip(time_stamps, handles, post_contents, URLs)):
print(time, handle, URL)
worksheet.write(row, col, time)
worksheet.write(row, col+1, handle)
worksheet.write(row, col+2, post)
worksheet.write(row, col+3, URL)
row = +1
我的問題是每個列表中只有第一和最后一項(time_stamps,handles,post_contents,URL)被寫入文件。
壓縮列表的長度相等(我使用print(len(list))
檢查了其他項目,但其他項目也不為空(也使用print
檢查了)。我做錯了什么?
一種系統地查找錯誤的方法是使用print語句,應該將行在每個循環中增加1,如果將print語句放在行之后,您應該能夠看到問題所在。
row = +1
print "row = %d" % row
我沒有第一次看到= +1。 但是row的值永遠不會改變。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.