您好,我是使用python3使用bs4和要求向我展示我想要的某辆车上所有清单的python3编码机器人的新手。不知道我是在正确编写代码还是缩进实际上是导致此问题的原因,所以不胜感激!
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
答案 0 :(得分:0)
def listing():
global listing
...
您在这里忘记了缩进