简体   繁体   中英

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM