ossama assaghir
ossama assaghir

Reputation: 308

How to fix - TabError: inconsistent use of tabs and spaces in indentation

I am trying to scrape questions from a web forum with python and BeautifulSoup library.

Here is how im trying to get the questions:

from bs4 import BeautifulSoup
import requests

url="https://forum.bouyguestelecom.fr/questions/browse?utf8=%E2%9C%93&flow_state=published&search=&order=created_at.desc"
req=requests.get(url).text

soup=BeautifulSoup(req, 'html.parser')
questions =soup.find_all("ul", class_="questions")

for question in questions:
    contents = soup.find_all("li", class_="questions-content first odd")
    for content in contents:
    ques=question.find("a", class_="content_permalink").text
    print(ques)

How the html looks like : html

first loop to get the ul with the class question

and then a loop to get the li inside of it

then get the content of the a

is my logic right ??

My issue :

    ques=question.find("a", class_="content_permalink").text
TabError: inconsistent use of tabs and spaces in indentation

Upvotes: 0

Views: 346

Answers (1)

HedgeHog
HedgeHog

Reputation: 25196

To fix your issue with the error adjust your indentation:

for content in contents:
    ques=question.find("a", class_="content_permalink").text
    print(ques)

instead of

for content in contents:
ques=question.find("a", class_="content_permalink").text
print(ques)

Upvotes: 2

Related Questions