IndentationError: expected an indented block discord.py
IndentationError: expected an indented block discord.py
你好,我完全不熟悉编码和使用 python3 的 discord 机器人,它利用 bs4 并请求向我显示我正在寻找的某辆车的所有列表。不确定我写的代码是否正确,或者缩进是否真的是这个问题的原因,任何建议将不胜感激!
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
...
你忘了在这里缩进
你好,我完全不熟悉编码和使用 python3 的 discord 机器人,它利用 bs4 并请求向我显示我正在寻找的某辆车的所有列表。不确定我写的代码是否正确,或者缩进是否真的是这个问题的原因,任何建议将不胜感激!
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
...
你忘了在这里缩进