【发布时间】:2020-02-16 23:39:08
【问题描述】:
所以我有代码:
import requests
import discord
from bs4 import BeautifulSoup
class MyClient(discord.Client):
async def on_ready(self):
print('Logged on as {0}!'.format(self.user))
async def on_message(self, message):
if (message.channel.id == 678447420643868674):
if "test" in message.content:
r = requests.get('https://www.jimmyjazz.com/mens/footwear/adidas-solar-hu-nmd/BB9528')
soup = BeautifulSoup(r.text, 'html.parser')
embed = discord.Embed(color=0x00ff00)
embed.title = "test"
for anchor_tag in soup.find_all(class_="box_wrapper")[0].findChildren():
if "piunavailable" in anchor_tag['class']:
embed.description = f"Size {anchor_tag.text} OOS"
await message.channel.send(embed=embed)
else:
embed.description = f"Size {anchor_tag.text} in stock!"
await message.channel.send(embed=embed)
client = MyClient()
client.run('NjY2MDMyMDc0NjM3MTgwOTQ4.XkjBLg.I3dtsL2nkVh_bafTlycSwBApQfU')
这会将商品库存作为每种尺寸的嵌入发送: https://gyazo.com/7a7c868d00a99fc3798a3c24feb9ea7e
我将如何更改代码以使其在一个嵌入中发送每个尺寸而不是每个尺寸的嵌入?
谢谢:)
【问题讨论】:
标签: beautifulsoup python-requests html-parsing discord.py