我正在使用Web抓取器,并使用它的结果,并通过discord命令将其打印出来,但是我一直遇到问题,它无法发送所有内容。
async def anime(ctx, *, input_by_user=None):
animespaces = input_by_user.replace(' ', '-').lower()
page_url = "https://www.crunchyroll.com/" + animespaces
uClient = uReq(page_url)
anime_soup = soup(uClient.read(), "html.parser")
episodes = anime_soup.findAll("p", {"class": "short-desc"})
eplist = len(episodes)
eplist -=1
t_end = time.time() + eplist # <--- I have even tried doing a + client.latency
# While toying with it I've found that giving it more time with + fixes it sort of but in the end doesn't work for multiple tests
while time.time() < t_end:
eplist -=1
title = episodes[eplist]
time.sleep(1)
eps = title.text.strip()
await ctx.send("Episode:" + " " + eps)
# If there are 5 episodes for example it may miss the last three or 2 or just 1 for instance
# -----OUTPUT------
# Episode 1: "episode"
# Episode 2: "episode"
# Episode 3: "episode"
# Episode 4: "episode"
# ----OUTPUT_END-----
# Here is where it will just stop and wont send anything further
答案 0 :(得分:0)
我最终只是用一段时间的True语句将其永久循环,直到达到0时它才停止。
eplist -=1
title = episodes[eplist]
eps = title.text.strip()
await ctx.send("Episode:" + " " + eps)
print(eplist)
if eplist == 0:
break
else:
print('its not done')