def hots_free(self, ctx):
"""Retrieves the Heroes of the Storm free rotation."""
url = "http://us.battle.net/heroes/en/"
soup = BeautifulSoup(urlopen(url), 'html5lib')
parsedText = [] ## End result: finds cleaned text from HTML
freeHeroes = [] ## Index of all free heroes found
freeIndicator = "|| Free" ## This is what Blizzard uses to indicate free heroes in their webpage
for elem in soup.find_all('li'):
if "free-rotation" in str(elem):
index = str(elem).find(freeIndicator)
## General area of where the string needed is. I'm lazy. ##
parsedText.append(str(elem)[index-100:index+100])
## Find text via regex ##
for string in parsedText:
result = re.search('data-analytics-placement="(.*) Free"', string)
freeHeroes.append(result.group(1)[0:-3])
## Formats via Discord's markdown ##
botText = "```md\n<Free-Rotation>```" + "```"
for hero in freeHeroes:
botText += hero+", "
botText = botText[0:-2] + "```"
await self.bot.say(botText)
评论列表
文章目录