Issue
I'm trying to scrape recent releases of movies with the URL. But I want to be notified of each new release. I also want to set a timer, let's say every two hours the script will check for a new movie release. If there's a new release, it would be sent to my Telegram bot. I have no idea on how to go about that yet.
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)
Solution
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)
Thanks so much @Aladdin Jiroun!
Answered By - Chigstardan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.