python这段编程提示 list index out of range求解
伊谢尔伦
伊谢尔伦 2017-04-18 10:11:10
0
3
1101

这段编程总提示list index out of range,看半天想不通~求解代码如下


def saveData(datalist,savepath):

book=xlwt.Workbook(encoding='utf-8',style_compression=0) sheet=book.add_sheet('豆瓣最受欢迎影评',cell_overwrite_ok=True) col=('标题','作者','影片名','影片详情链接','推荐级','回应数','影评链接','影评','有用数') for i in range(0,9): sheet.write(0,i,col[i])#列名 for i in range(0,50):#总共50条影评 data=datalist[i] for j in range(0,9): sheet.write(i+1,j,data[j])#数据 book.save(savepath)#保存

def main():

baseurl='http://movie.douban.com/review/best/?start=' datalist=getData(baseurl) savapath=u'豆瓣最受欢迎影评.xlsx' saveData(datalist,savapath)

main()

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all (3)
左手右手慢动作

The list is out of bounds. Are you sure the length of each datalist is 9? Is it possible that when crawling a web page, some data is missing and not assigned a value? As a result, each datalist may have different lengths. Causefor j in range(0,9)When data[j] goes out of bounds?

    小葫芦

    I agree with the above. The information given by the poster is incomplete and there is no contextual information about the error. You can only print it out and compare it yourself.

      洪涛

      The list is out of bounds, why didn’t I post the error message

        Latest Downloads
        More>
        Web Effects
        Website Source Code
        Website Materials
        Front End Template
        About us Disclaimer Sitemap
        php.cn:Public welfare online PHP training,Help PHP learners grow quickly!