Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- from bs4 import BeautifulSoup
- import notify2
- URL = "https://sverhestestvennoe.live/seasons/15s-06/"
- # имитация браузера, а не скрипта
- HEADERS = {'user-agent':'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36',
- 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9'}
- # params - это опциональный параметр, который иногда присутствует, к примеру, это может быть номер страницы на сайте
- def get_html(url):
- r = requests.get(url, headers = HEADERS,);
- return r
- def get_content(html):
- # в конструкторе объекта BF в качестве второго аргумента передан тип документа с которым мы работаем
- soup = BeautifulSoup(html, 'html.parser')
- episods = soup.find('ul', class_ = 'episodios').find_all('div', class_= 'numerando')# find_all - return list
- numeric = len(episods)+1
- try:
- with open('old_series.txt', 'r') as f:
- old_value = int(f.read())
- except IOError:
- with open('old_series.txt', 'w') as f:
- f.write(str(numeric));
- if(old_value != numeric):
- print("New episod!")
- notify2.init("backup")
- n = notify2.Notification("BBR Checker Series", "New episod")
- n.show()
- with open('old.series.txt', 'w') as f:
- f.write(str(numeric));
- else:
- print("No new episod!")
- # part = [] # словарь для серии и названия
- #for episod in episods:
- # part.append({
- # 'data of reliase': episod.find('span', class_='date').get_text()
- # })
- def parse():
- html = get_html(URL);
- # при выводе print(html.status_code) получим response[200], а все коды, что меньше, чем 400, это корректно совершенный запрос.
- if html.status_code == 200:
- get_content(html.text) # передаем готовый html в качестве текста
- else:
- print('Error')
- if __name__ == '__main__':
- parse()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement