Files
daily-blackout-check/blockout.py
2024-11-16 23:37:47 +03:30

21 lines
550 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import requests
from bs4 import BeautifulSoup
def get_main_page() -> str:
return requests.get('https://www.qepd.co.ir/').text
def find_blockout_link(html: str) -> None | str:
soup = BeautifulSoup(html, 'html.parser')
a_tags = soup.find_all('a', href=True)
for a_tag in filter(lambda tag: 'اطلاعات برنامه خاموشی ها' in tag.text, a_tags):
return a_tag.get('href')
return None
page = get_main_page()
link = find_blockout_link(page)
if not link:
raise Exception('unable to find blockout link!')