IndentationError:预期出现缩进块discord.py

问题描述 投票:-1回答:1

[您好,我是使用python3使用bs4和要求的ord3机器人进行编码和开发的全新工具,并向我展示了我正在寻找的特定汽车上的所有列表。不知道我是在正确编写代码,还是缩进实际上是导致此问题的原因,任何建议将不胜感激!

import discord
from discord.ext import commands
import requests
import bs4
import lxml

req = requests.get('https://dallas.craigslist.org/search/cto?query=300zx')
soup = bs4.BeautifulSoup(req.text, 'lxml')

client = commands.Bot(command_prefix = '!')

@client.event
async def on_ready():
    print('Bot is ready.')

@client.command()
async def search(ctx):
    listings = soup.findAll('li', class_='result-row')
    listing1 = listings[0]
    def listing():
    global listing1
    for listing1 in listings:
        title = listing1.p.a.text
        link = listing1.p.a['href']
        price = listing1.span.text
    await ctx.send(f'Title: {title}\nLink: {link}\nPrice: {price}')

client.run('token')

  File "bot.py", line 21
    global listing1
         ^
IndentationError: expected an indented block
python for-loop beautifulsoup indentation discord.py
1个回答
0
投票
def listing():
    global listing
    ...

您在这里忘记了缩进

© www.soinside.com 2019 - 2024. All rights reserved.