General.py 文件源码

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

项目:paobot-Release 作者: cjoeml 项目源码 文件源码
def THP(self, ctx, link): ## ctx is an invisible parameter ##
        """Dead site."""
        author = ctx.message.author.id
        frontpage = []
        threads = []
        frontpage_str = ''
        try:
            url = link ## build the web address ##
            soup = BeautifulSoup(urlopen(url), 'html5lib')
        except Exception:
            url = "https://" + link
            soup = BeautifulSoup(urlopen(url), 'html5lib')
        try:
            for elem in soup.find_all('li'):
                if "@" in str(elem):
                    frontpage.append(str(elem)[4:17] + " - " + str(elem.a.contents)[2:-2])

            if frontpage:
                for link in frontpage:
                    frontpage_str += link + '\n'

            else:
                for elem in soup.select('span[id]'):
                    if "hidden." in str(elem):
                        regex_str = re.search('>(.*?)</a>', str(elem))
                        if regex_str:
                            threads.append(regex_str.group(1))

                for thread in threads:
                    for elem in soup.find_all("input", value=thread):#, string=thread):
                        regex_str = re.search('>[\r\n]+(.*?)[\r\n]+</span>', str(elem.find_next()))
                        if regex_str:
                            frontpage.append(regex_str.group(1))

                for link in frontpage:
                    frontpage_str += link + '\n'
            await self.bot.say("```" + frontpage_str + "```")
        except Exception as e:
            await self.bot.say("Try a valid link.")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号