1

I'm building a webcrawler in python. It is crawling an news site. but when i am getting this error:TabError: inconsistent use of tabs and spaces in indentation. it is in line 28 in my script. I can't figure out how to solve it.

    import requests
    from lxml import html
    import time
    from colorama import *

    def crawl():
        URL = "http://www.svt.se/nyheter/"
        host = "http://www.svt.se"
        blankHTML = requests.get(URL)
        tree = html.fromstring(blankHTML.text)
        Nyheter = tree.xpath('//span[@class="nyh_teaser__heading-title"]/text()')
        beskrivning = tree.xpath('//span[@class="nyh_teaser__text"]/text()')
        link = tree.xpath('//a[@class="nyh_teaser__link"]/@href')
        link_list = []
        newsnumber = 0
        numbersOfNews = 0
        for numb in range(1,10):
            print(Fore.GREEN + "Titel: " + Nyheter[newsnumber])
            print(Fore.YELLOW + "Beskrivning: " + beskrivning[newsnumber])
            print(link[newsnumber])
            link_list.append(link)
            newsnumber += 1
        choice1 = input("<News> ").lower()
        while True:
            if choicel == 1:
                URL = host + link_list[0]
                blankHTMLS = requests.get(URL)
                treek = html.fromstring(blankHTMLS.text)
                wholeNew = treek.xpath('//div[@class="nyh_article__body]/p/text()')
                print(wholeNew)






    crawl()
Hagge15
  • 19
  • 2

1 Answers1

0

Your error would be caused by mixing tabs and spaces for your indentation. They were lost when you pasted your code example here so I am unable to reproduce the issue. You can use either but you can't mix them in the same code block. You can try opening your python file with something like Notepad++ and enabling View > Show Symbol > Show White Spaces and TAB.

I also noticed some other errors that may trip you up. You have an infinite loop so your program will never finish. Also you create a variable called choice1 but later refer to it as choicel which will cause an error.

Community
  • 1
  • 1
Igor
  • 1,212
  • 12
  • 23