我如何使用此代码的输出和 Telegram API 来提醒我有新条目?
How can I use the output of this code and the Telegram API to alert me of a new entry?
我正在尝试使用 URL 抓取最近发行的电影。但我想收到每个新版本的通知。我还想设置一个计时器,假设脚本每两个小时检查一次新电影的发布。如果有新版本,它会发送到我的 Telegram 机器人。我还不知道该怎么做。
from bs4 import BeautifulSoup
from urllib.request import Request, urlopen
req = Request("https://www.thenetnaija.com/videos/movies", headers={'User-Agent': 'XYZ/3.0'})
webpage = urlopen(req, timeout=10)
b4 = BeautifulSoup(webpage, "html.parser")
movie_list = b4.find_all("div", {"class" : "video-files"})
for allContainers in movie_list:
filmName = allContainers.find('img').get('alt')
print(filmName)
从电报机器人为您发送通知
1 - 首先与这个机器人交谈:@userinfobot
获取 id
2 - 从@botfather
获取你的机器人令牌
3 - 向您的机器人发送任何消息
(以上步骤只需一次)
4- make get 请求
https://api.telegram.org/bot{bot_token}/sendMessage?chat_id={chat_id}&text={notification_text}
import time
from bs4 import BeautifulSoup
import requests
from urllib.request import Request, urlopen
req = Request("https://www.thenetnaija.com/videos/movies", headers={'User-Agent': 'XYZ/3.0'})
webpage = urlopen(req, timeout=10)
b4 = BeautifulSoup(webpage, "html.parser")
movie_list = b4.find_all("div", {"class" : "video-files"})
for allContainers in movie_list:
filmName = allContainers.find('img').get('alt')
printed = []
print(filmName)
while True:
if filmName not in printed:
requests.get("https://api.telegram.org/bot{"insert bot_token here"}/sendMessage?chat_id={"insert chat id here"}&text={}".format(filmName))
time.sleep(10)
printed.append(filmName)
非常感谢@Aladdin Jiroun!
我正在尝试使用 URL 抓取最近发行的电影。但我想收到每个新版本的通知。我还想设置一个计时器,假设脚本每两个小时检查一次新电影的发布。如果有新版本,它会发送到我的 Telegram 机器人。我还不知道该怎么做。
from bs4 import BeautifulSoup
from urllib.request import Request, urlopen
req = Request("https://www.thenetnaija.com/videos/movies", headers={'User-Agent': 'XYZ/3.0'})
webpage = urlopen(req, timeout=10)
b4 = BeautifulSoup(webpage, "html.parser")
movie_list = b4.find_all("div", {"class" : "video-files"})
for allContainers in movie_list:
filmName = allContainers.find('img').get('alt')
print(filmName)
从电报机器人为您发送通知
1 - 首先与这个机器人交谈:@userinfobot 获取 id
2 - 从@botfather
获取你的机器人令牌3 - 向您的机器人发送任何消息
(以上步骤只需一次)
4- make get 请求
https://api.telegram.org/bot{bot_token}/sendMessage?chat_id={chat_id}&text={notification_text}
import time
from bs4 import BeautifulSoup
import requests
from urllib.request import Request, urlopen
req = Request("https://www.thenetnaija.com/videos/movies", headers={'User-Agent': 'XYZ/3.0'})
webpage = urlopen(req, timeout=10)
b4 = BeautifulSoup(webpage, "html.parser")
movie_list = b4.find_all("div", {"class" : "video-files"})
for allContainers in movie_list:
filmName = allContainers.find('img').get('alt')
printed = []
print(filmName)
while True:
if filmName not in printed:
requests.get("https://api.telegram.org/bot{"insert bot_token here"}/sendMessage?chat_id={"insert chat id here"}&text={}".format(filmName))
time.sleep(10)
printed.append(filmName)
非常感谢@Aladdin Jiroun!