Please point out my mistake in the following program
Question: Here m trying to extract a list of blacklist IP from a specific site and
trying to make an excel sheet of the following fields : IP , date ...... New
updated code is :

    
    
    import xlwt
    import urllib
    
    def Bl():
        link = 'https://www.dshield.org/ipsascii.html?limit=100'
        p = urllib.urlopen(link)
        text = p.readlines()
    
    
        wbk = xlwt.Workbook()
        sheet = wbk.add_sheet('python')
        sheet.write(0,0,'Blacklist IP')
        sheet.write(0,1,'Reports')
        sheet.write(0,2,'abcd')
        sheet.write(0,3,'date')
        sheet.write(0,4,'Date')
    
        row = 1 #counter for rows.
        col = 0 #counter for columns.
        x = 0   #counter for printing the n'th element in the string w.
    
        for line in text:
            li = line.strip()
            w = line.split()
    
    
            if not li.startswith("#"):
                sheet.write(row,col,w[0])
                sheet.write(row,1,w[1])
                sheet.write(row,2,w[2])
                sheet.write(row,3,w[3])
                sheet.write(row,4,w[4])
                row = row + 1
    
        wbk.save('new.xls')
    
    Bl()
    


Answer: I believe it should be this, though my python isn't great:

    
    
    import xlwt
    import urllib
    
    link = 'https://www.dshield.org/ipsascii.html?limit=100'
    p = urllib.urlopen(link)
    text = p.readlines()
    
    
    wbk = xlwt.Workbook()
    sheet = wbk.add_sheet('Blacklist IP')
    
    row = 1 #counter for rows.
    col = 0 #counter for columns.
    #x = 0   #counter for printing the n'th element in the string w.
    
    for line in text:
        li = line.strip()
        w = line.split()
        print "The line " + line + " was split into " + len(w) + " size"
    
        for i in range(0,len(w)-1):
            if not li.startswith("#") and not li.isspace():
                sheet.write(row,col,w[i])
                #x = x + 1      
                col = col + 1
                if col > 256:
                    print "Line of " + li
                    print "Row: " + row
                    print "Col: " + col
                    raise ValueError('Too many columns, can\'t insert ' + w)
    
        row = row + 1
    
    wbk.save('new.xls')
    

Reasoning is that I believe you should be changing column every time you write
a value, since that appears to be causing your current error. I also believe
You should be changing row after each line, not just at the end of the code
which then appears superfluous

[Edit update after user feedback]

