i got problems in my codes,but i cant find them........ #3603
Unanswered
univertion
asked this question in
Q&A
Replies: 1 comment
-
Please have a look at Introduction to the APII so you know the code is to be structured. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
i want to build a telegram bot to send me a random SCP artical everyday, but after my code run on python ,nothing has changed, my bot didnt send me anything,plz give me noob a hand :(.
here is code:
机器人的token
TOKEN = "yourtoken"
建立连接
bot = telegram.Bot(token=TOKEN)
爬虫函数
def get_scp_article():
# 访问随机文章的URL
url = "http://scp-wiki-cn.wikidot.com/random:random-scp"
response = requests.get(url)
# 使用BeautifulSoup解析页面内容
soup = BeautifulSoup(response.content, "html.parser")
# 获取文章标题
title = soup.find("div", {"class":"scp-header"}).h1.text.strip()
# 获取文章内容
content = soup.find("div", {"id":"page-content"}).text.strip()
return title, content
发送随机文章
def send_random_article():
# 随机获取一篇文章
title, content = get_scp_article()
# 发送给用户
bot.send_message(chat_id="yourchatid", text=title+"\n"+content)
设置定时任务,每天早晨8点发送文章
schedule.every().day.at("08:00").do(send_random_article)
循环运行
while True:
schedule.run_pending()
time.sleep(1)
Beta Was this translation helpful? Give feedback.
All reactions