代码之家  ›  专栏  ›  技术社区  ›  FanMan

应为缩进块[已关闭]

  •  -4
  • FanMan  · 技术社区  · 6 年前

    我一直收到警告说

    “需要缩进块”

    在最后一行,但不能确切地知道问题是什么。我只需要代码运行而不需要问题。我可以删除引起这个问题的任何内容,或者现在就发表评论。

    def Weather():
        zipcode = input('Please enter zipcode: ')
        wcpage = requests.get('https://weather.com/weather/today/l/' + zipcode,verify=False)
        soup2= BeautifulSoup(wcpage.text, 'html.parser')
        (soup2.prettify())
        print(soup2.find_all('body'))
        for tr in soup2.find_all('body', class_="weather"):
    Weather()
    
    2 回复  |  直到 6 年前
        1
  •  4
  •   Burton2000    6 年前

    正如注释中所提到的,weather()函数中的最后一行是一个for循环,该循环未完成,这在python中是不允许的。如果您不想在这个循环中做任何事情,您应该使用pass关键字,如下所示:

    for tr in soup2.find_all('body', class_="weather"):
        pass
    
        2
  •  0
  •   DariusFontaine    6 年前

    你的循环需要做些什么。要不执行任何操作,请使用“pass”关键字。

    def Weather():
        zipcode = input('Please enter zipcode: ')
        wcpage = requests.get('https://weather.com/weather/today/l/' + zipcode,verify=False)
        soup2= BeautifulSoup(wcpage.text, 'html.parser')
        (soup2.prettify())
        print(soup2.find_all('body'))
        for tr in soup2.find_all('body', class_="weather"):
            """DO SOMETING HERE"""
    Weather()