[您好,我是使用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
def listing():
global listing
...
您在这里忘记了缩进