def _location_pokemon(self, *, poke: str):
"""Get a Pokémon's catch location.
Example !pokedex location voltorb
"""
location_url = "http://pokemondb.net/pokedex/{}".format(poke)
with aiohttp.ClientSession() as session:
async with session.get(location_url) as response:
soup = BeautifulSoup(await response.text(), "html.parser")
loc = []
version = []
div = soup.find('div', attrs={'class': 'col desk-span-7 lap-span-12'})
table = div.find('table', attrs={'class': 'vitals-table'})
cols = [ele.text.strip() for ele in table.find_all('td') if ele]
loc.append(cols)
tcols = [ele.strings for ele in table.find_all('th') if ele]
version.append([', '.join(x) for x in tcols])
# We have to extract out the base index, because it scrapes as
# a list of a list. Then we can stack and tabulate.
extract_loc = loc[0]
extract_version = version[0]
m = list(zip(extract_version, extract_loc))
t = tabulate(m, headers=["Game Version", "Location"])
await self.bot.say("```{}```".format(t))
评论列表
文章目录