Как отправить встраиваемое сообщение, содержащее несколько ссылок, проанализированных с веб-сайта, на веб-крючок? - PullRequest
3 голосов
/ 15 октября 2019

Я хочу, чтобы мое сообщение для встраивания выглядело так, но мое возвращает только одну ссылку.

enter image description here

Вот мой код:

import requests
from bs4 import BeautifulSoup
from discord_webhook import DiscordWebhook, DiscordEmbed

url = 'https://www.solebox.com/Footwear/Basketball/Lebron-X-JE-Icon-QS-variant.html'
headers = {'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36'}
r = requests.get(url, headers=headers)
soup = BeautifulSoup(r.content, "lxml")
for tag in soup.find_all('a', class_="selectSize"):
    #There's multiple 'id' resulting in more than one link
    aid = tag.get('id')
    #There's also multiple sizes
    size = tag.get('data-size-us')
    #These are the links that need to be shown in the embed message
    product_links = "https://www.solebox.com/{0}".format(aid)

webhook = DiscordWebhook(url='WebhookURL')
embed = DiscordEmbed(title='Title')
embed.set_author(name='Brand')
embed.set_thumbnail(url="Image")
embed.set_footer(text='Footer')
embed.set_timestamp()
embed.add_embed_field(name='Sizes', value='US{0}'.format(size))
embed.add_embed_field(name='Links', value='[Links]({0})'.format(product_links))
webhook.add_embed(embed)
webhook.execute()
...