pokedex.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:Jumper-Cogs 作者: Redjumpman 项目源码 文件源码
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))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号