各位前輩好
問題為小弟想把網頁爬出的每一頁每一個品項資料依序寫入excel
但輸出至excel的結果都是最後一頁最後一個品項重複寫入1~rows
原始碼如下,請問該如何修改,謝謝~
dict = {};
page = 10
rows = page*10
w = xlwt.Workbook()
path_excel = '/home/pi/data/'+filename+'.xls'
t = w.add_sheet('ZH',cell_overwrite_ok=True)
for i in range(page): #頁數迴圈
dict['resp%d' % (i+1)] = opener.open('http://www.zowhong.com.tw/order/s
earch.php?page=%d' % (i+1)).read()
soup = BeautifulSoup(dict['resp%d' % (i+1)]) #soup每一頁
quantity = len(soup.select('.f01')) #偵測每頁品項數量
for j in range(quantity): #先輸出所有f01品項,f02價格
print soup.select('.f01')[j].text.strip(), soup.select('.f02')[
for k in range(rows): #行數迴圈
t.write(k,0,soup.select('.f01')[j].text.strip())
t.write(k,1,soup.select('.f02')[j].text)
w.save(path_excel)