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.")
评论列表
文章目录