{"id":337867,"date":"2022-09-03T03:00:09","date_gmt":"2022-09-03T03:00:09","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=337867"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=337867","title":{"rendered":"<span>Telegramm-habr-\u0431\u043e\u0442. \u0414\u043e\u043b\u0433\u0438\u0439 \u043f\u0443\u0442\u044c \u043a \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u0441\u0442\u0432\u0443<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u0434\u0435\u043d\u044c \u043c\u044b \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c\u00a0habr. \u041a\u0430\u0436\u0434\u044b\u0439 \u0434\u0435\u043d\u044c \u0437\u0430\u0445\u043e\u0434\u0438\u043c \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u0443\u044e \u043b\u0435\u043d\u0442\u0443 \u0438 \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c \u0435\u0451. \u0427\u0442\u043e, \u0435\u0441\u043b\u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440?<\/p>\n<p>\u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u044f \u043f\u0438\u0441\u0430\u043b\u00a0telegram-\u0431\u043e\u0442\u0430 \u043d\u0430\u00a0python3, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0442\u0430\u0441\u043a\u0438\u0432\u0430\u0435\u0442 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u0441\u0442\u0430\u0442\u0435\u0439 \u0441 <a href=\"https:\/\/habr.com\/ru\/all\/\" rel=\"noopener noreferrer nofollow\">habr<\/a> \u0438 \u043f\u0438\u0448\u0435\u0442 \u0438\u0445 \u0432\u00a0telegram.<\/p>\n<h2>\u041a\u0430\u043a \u044d\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c?<\/h2>\n<p>\u0423\u00a0python3 \u0435\u0441\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u2013\u00a0beautiful\u00a0soap\u00a04. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u044d\u0442\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043c\u043e\u0436\u043d\u043e\u00a0<strong>\u043f\u0430\u0440\u0441\u0438\u0442\u044c<\/strong>\u00a0\u0441\u0430\u0439\u0442\u044b.\u00a0<\/p>\n<p>\u041f\u0430\u0440\u0441\u0438\u043d\u0433 (parsing) \u2014 \u044d\u0442\u043e\u00a0<strong>\u0441\u0431\u043e\u0440 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0438\u0437 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432 \u0438 \u0441\u0430\u0439\u0442\u043e\u0432 \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0446\u0435\u043b\u044f\u0445, \u043e\u0442 \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0438 \u0434\u043e \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/strong>, \u043f\u0440\u043e\u0441\u0442\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u044d\u0442\u043e \u0441\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432.<\/p>\n<p>\u041f\u0440\u043e\u0441\u0442\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u044f \u043f\u0438\u0448\u0443 \u0441\u043a\u0440\u0438\u043f\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0442\u0430\u0441\u043a\u0438\u0432\u0430\u0435\u0442 \u0438\u0437 \u0441\u0430\u0439\u0442\u0430 \u043a\u0430\u043a\u0443\u044e-\u0442\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e (\u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u0441\u0442\u0430\u0442\u0435\u0439). \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0435 \u0441\u0430\u0439\u0442\u043e\u0432 \u00a0<a href=\"https:\/\/dvmn.org\/encyclopedia\/modules\/bs4-tutorial\/\" rel=\"noopener noreferrer nofollow\"><u>\u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0437\u0434\u0435\u0441\u044c<\/u><\/a><u>.<\/u><\/p>\n<p>\u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0432\u0438\u0434\u0435\u0442\u044c \u043f\u043e \u201c\u044d\u0442\u043e\u043c\u0443\u201d \u0441\u043a\u0440\u0438\u043d\u0443,\u00a0<\/p>\n<figure class=\"float bordered\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/74d\/c79\/1af\/74dc791aff28f50ea784210627ee6d62.png\" alt=\"&quot;\u044d\u0442\u043e\u0442&quot; \u0441\u043a\u0440\u0438\u043d\" title=\"&quot;\u044d\u0442\u043e\u0442&quot; \u0441\u043a\u0440\u0438\u043d\" width=\"451\" height=\"272\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/74d\/c79\/1af\/74dc791aff28f50ea784210627ee6d62.png\"\/><figcaption>&#171;\u044d\u0442\u043e\u0442&#187; \u0441\u043a\u0440\u0438\u043d<\/figcaption><\/figure>\n<p>\u041a\u0430\u0436\u0434\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u0432 \u0445\u0430\u0431\u0440\u0435 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0442\u044d\u0433\u043e\u0432 \u201c\u00a0article\u201d\u00a0\u00a0\u0441\u043e \u0441\u0432\u043e\u0438\u043c\u00a0id.<\/p>\n<p>\u00a0<\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e, \u043f\u043e\u043a\u0430 \u043e\u043d\u0430 \u043d\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u0442 \u0441\u00a0id. \u042d\u0442\u043e\u0442 \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u0447\u0435\u043d\u044c \u0434\u043e\u043b\u0433\u0438\u0439. \u041d\u0430\u0434\u043e \u0436\u0434\u0430\u0442\u044c, \u043f\u043e\u043a\u0430\u00a0python3 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442 ~700\u00a0000 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439!\u00a0<\/p>\n<p>\u0415\u0441\u0442\u044c \u0434\u0440\u0443\u0433\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442. \u041c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432\u0441\u0435 \u0442\u044d\u0433\u0438 \u201c\u00a0article\u201d, \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0438\u0435 \u0437\u0430 \u0441\u0442\u0430\u0442\u044c\u0438, \u0438 \u043f\u043e\u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0442\u044c \u044d\u0442\u0438 \u0442\u044d\u0433\u0438. \u0426\u0438\u043a\u043b \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f, \u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0434\u0435\u043b\u0430\u0442\u044c \u0443\u0436\u0435 20(\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0430\u0442\u0435\u0439 \u043d\u0430 \u0433\u043b\u0430\u0432. \u044d\u043a\u0440\u0430\u043d\u0435) \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439.<\/p>\n<pre><code class=\"python\">from itertools import count from re import I import requests from bs4 import BeautifulSoup  url2 = \"https:\/\/habr.com\/ru\/all\/\" response2 = requests.get(url2) response2.raise_for_status()  soup2 = BeautifulSoup(response2.text, \"lxml\") tag = soup2.find_all(\"article\", class_=\"tm-articles-list__item\")  for i in range(0, 10):     out = tag[i].find(\"h2\").find(\"span\").text     print(out + \" url: \" + \"https:\/\/habr.com\" + urlOut)<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438\u043a\u043b\u0435\u0435\u0432\u044b\u0435\u043c \u044d\u0442\u043e\u0442 \u043a\u0443\u0441\u043e\u043a \u043a\u043e\u0434\u0430 \u043a\u00a0pyTelegramBotAPI:<\/p>\n<pre><code class=\"python\">import requests from bs4 import BeautifulSoup import telebot  bot = telebot.TeleBot(\"TOKEN\")  url2 = \"https:\/\/habr.com\/ru\/all\/\" response2 = requests.get(url2) response2.raise_for_status()  soup2 = BeautifulSoup(response2.text, \"lxml\") tag = soup2.find_all(\"article\", class_=\"tm-articles-list__item\")  @bot.message_handler(commands=[\"start\"]) def start(m, res=False):     bot.send_message(m.chat.id, \"Bot is started.\")  @bot.message_handler(commands=[\"habr\"]) def habr(message):     global url2     response2 = requests.get(url2)     response2.raise_for_status()      soup2 = BeautifulSoup(response2.text, \"lxml\")     tag = soup2.find_all(\"article\", class_=\"tm-articles-list__item\")     for i in range(0, 10):         out = tag[i].find(\"h2\").find(\"span\").text         bot.send_message(message.chat.id, out)  bot.polling(none_stop=True, interval=0)<\/code><\/pre>\n<p>\u041e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u043d\u043e \u043f\u0440\u0438\u043a\u0440\u0435\u043f\u0438\u0442\u044c \u044d\u0442\u0438 \u0441\u0442\u0440\u043e\u0447\u043a\u0438 \u0432 \u0444\u0443\u043d\u0446\u0438\u044e\u00a0habr, \u0442.\u043a. \u0435\u0441\u043b\u0438 \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u043d\u0430\u0448 \u0431\u043e\u0442 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u0441\u044f.<\/p>\n<p>\u042d\u0442\u0438\u00a0\u0441\u0442\u0440\u043e\u0447\u043a\u0438:<\/p>\n<pre><code class=\"python\">response2 = requests.get(url2) response2.raise_for_status()  soup2 = BeautifulSoup(response2.text, \"lxml\") tag = soup2.find_all(\"article\", class_=\"tm-articles-list__item\")<\/code><\/pre>\n<p>\u042d\u0442\u043e \u043f\u043e\u043a\u0430 \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u0443\u0434\u043e\u0431\u043d\u043e! \u0421\u0441\u044b\u043b\u043a\u0438-\u0442\u043e \u043d\u0435\u0442\u0443!\u00a0<\/p>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0441\u043e \u0441\u0441\u044b\u043b\u043a\u043e\u0439 \u043b\u0435\u0433\u043a\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c. \u041d\u0430\u0434\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u0443 \u0441\u0442\u0440\u043e\u0447\u043a\u0443 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e\u00a0\u201chabr\u201d:<\/p>\n<pre><code class=\"python\">urlOut = \"https:\/\/habr.com\" + tag[i].find(\"h2\").find(\"a\").get(\"href\")<\/code><\/pre>\n<p>\u0418 \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0432\u044b\u0432\u043e\u0434 \u0441 &#171;out&#187; \u043d\u0430 &#171;out\u00a0+\u00a0&#187; url: &#187;\u00a0+\u00a0urlOut&#187;.<\/p>\n<p>\u0412\u043e\u0442,\u00a0\u00a0\u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0432\u00a0telegram:<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/126\/a0f\/bb0\/126a0fbb0772c4ace5f90bd85ef8a99f.png\" width=\"451\" height=\"480\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/126\/a0f\/bb0\/126a0fbb0772c4ace5f90bd85ef8a99f.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412\u044b\u0432\u043e\u0434 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0440\u0435\u0437\u043a\u0438\u0439 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f. \u041d\u0430\u0434\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0443 \u043c\u0435\u0436\u0434\u0443 \u043a\u0430\u0436\u0434\u044b\u043c \u0432\u044b\u0432\u043e\u0434\u043e\u043c.<\/p>\n<p>\u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c\u00a0sleep\u00a0\u0438\u0437\u00a0time:<\/p>\n<pre><code class=\"python\">from time import sleep<\/code><\/pre>\n<p>\u0418 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0443 \u0432 \u0446\u0438\u043a\u043b:<\/p>\n<pre><code class=\"python\">for i in range(0, 10):         out = tag[i].find(\"h2\").find(\"span\").text         urlOut = \"https:\/\/habr.com\" + tag[i].find(\"h2\").find(\"a\").get(\"href\")         bot.send_message(message.chat.id, out + \"url: \" + urlOut)         sleep(5)<\/code><\/pre>\n<p>\u0412\u00a0telegram\u00a0\u0432\u0441\u0451 \u0442\u043e\u0436\u0435-\u0441\u0430\u043c\u043e\u0435, \u043d\u043e \u043c\u0435\u0436\u0434\u0443 \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435\u0439 \u2013 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0430.<\/p>\n<p>\u0418 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u043e\u0432\u043e\u0441\u0442\u0438:<\/p>\n<pre><code class=\"python\">@bot.message_handler(commands=[\"news\"]) def habr(message):     global url     response2 = requests.get(url)     response2.raise_for_status()      soup2 = BeautifulSoup(response2.text, \"lxml\")     tag = soup2.find_all(\"article\", class_=\"tm-articles-list__item\")     for i in range(0, 10):         out = tag[i].find(\"h2\").find(\"span\").text         urlOut = \"https:\/\/habr.com\" + tag[i].find(\"h2\").find(\"a\").get(\"href\")         bot.send_message(message.chat.id, out + \"url: \" + urlOut)         sleep(5)<\/code><\/pre>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a31\/b56\/b1b\/a31b56b1bd2e0fcb15a35aed9c83d401.png\" width=\"451\" height=\"274\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a31\/b56\/b1b\/a31b56b1bd2e0fcb15a35aed9c83d401.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0417\u043d\u0430\u0435\u0442\u0435, \u0447\u0442\u043e \u044f \u0432\u0430\u043c \u0441\u043a\u0430\u0436\u0443? \u042d\u0442\u043e \u043e\u043f\u044f\u0442\u044c \u043d\u0435\u0443\u0434\u043e\u0431\u043d\u043e! \u0410 \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u044f \u043d\u0435 \u0437\u0430\u0445\u043e\u0447\u0443 \u0447\u0438\u0442\u0430\u0442\u044c \u0434\u0430\u043b\u044c\u0448\u0435? \u041d\u0443\u0436\u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0430, \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0430\u044f \u0437\u0430 \u0441\u0442\u043e\u043f. \u041f\u043e\u0438\u0437\u0443\u0447\u0430\u0432, \u043a\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u044f \u043d\u0430\u0448\u0435\u043b \u0438\u00a0url-\u043a\u043d\u043e\u043f\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u043d\u0430 \u0441\u0430\u0439\u0442. \u041e\u0442\u0434\u0435\u043b\u044c\u043d\u0430\u044f \u043a\u043d\u043e\u043f\u043a\u0430 \u043a\u0440\u0430\u0441\u0438\u0432\u0435\u0435, \u0447\u0435\u043c \u0442\u0443\u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0430! \u041a\u043e\u0440\u043e\u0447\u0435, \u0434\u0435\u043b\u0430\u0435\u043c \u0434\u0432\u0435\u00a0Inline\u00a0\u043a\u043d\u043e\u043f\u043a\u0438.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u043e \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u201chabr\u201d \u0438 \u201cnews\u201d \u044d\u0442\u0438 \u0441\u0442\u0440\u043e\u043a\u0438:<\/p>\n<pre><code class=\"python\">markup = types.InlineKeyboardMarkup(row_width=2) btn_url = types.InlineKeyboardButton(text=\"Go to habr.\", url=urlOut) btn_stop = types.InlineKeyboardButton(text=\"STOP IT!\", callback_data=\"stop\") markup.add(btn_url, btn_stop)<\/code><\/pre>\n<p>\u0438\u00a0\u0434\u043b\u044f\u00a0\u201chabrNews\u201d :<\/p>\n<pre><code class=\"python\">markup = types.InlineKeyboardMarkup(row_width=2) btn_url = types.InlineKeyboardButton(text=\"Go to habr.\", url=urlOut) btn_stop = types.InlineKeyboardButton(text=\"STOP IT!\", callback_data=\"stop_news\") markup.add(btn_url, btn_stop)<\/code><\/pre>\n<p>\u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0432\u00a0bot.send_message. \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"python\">bot.send_message(message.chat.id, out + \"url: \" + urlOut, reply_markup=markup)<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0441\u043e\u0431\u044b\u0442\u0438\u044f\u00a0callback\u00a0\u043a\u043d\u043e\u043f\u043a\u0438:<\/p>\n<pre><code class=\"python\">@bot.callback_query_handler(func=lambda call:True) def call_repley(call):     if call.message and call.data == \"stop\":         None<\/code><\/pre>\n<p>\u0418 \u0432\u043e\u0442 \u0442\u0443\u0442 \u044f \u043f\u0440\u044f\u043c \u0432\u0441\u0442\u0430\u043b. \u042f \u043d\u0435 \u0437\u043d\u0430\u043b, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c! \u041c\u043d\u0435 \u043d\u0430\u0434\u043e \u0431\u044b\u043b\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0438\u0437 \u201ccall_repley\u201d \u0432 \u201chabr\u201d. \u0412\u00a0habr\u0415 \u0443\u043c\u043d\u044b\u0435 \u0434\u044f\u0434\u044c\u043a\u0438 \u043f\u0438\u0448\u0443\u0442, \u0447\u0442\u043e \u043b\u0443\u0447\u0448\u0438\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u044d\u0442\u043e \u0447\u0435\u0440\u0435\u0437\u00a0callback_data, \u043d\u043e \u044f 12-\u0442\u0438 \u043b\u0435\u0442\u043d\u0438\u0439 \u043f\u0430\u0446\u0430\u043d! \u041c\u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0441\u043b\u043e\u0436\u043d\u044b\u043c \u044d\u0442\u0430 \u0441\u0445\u0435\u043c\u0430. \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c,\u00a0\u00a0\u0447\u0442\u043e \u0443\u043c\u043d\u044b\u0435 \u0434\u044f\u0434\u044c\u043a\u0438 \u0438\u0437\u00a0habr\u0410 \u043f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c, \u043a\u0430\u043a \u043f\u0438\u0448\u0443\u0442 \u0447\u0435\u0440\u0435\u0437\u00a0callback_data, \u043f\u0438\u0448\u0443\u0442 \u0447\u0435\u0440\u0435\u0437 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435. \u042f \u043d\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u043b, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0433\u043b\u0430\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0434\u043e \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u043b\u00a0<a href=\"https:\/\/habr.com\/ru\/post\/675404\/\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u0443 \u0441\u0442\u0430\u0442\u044c\u044e<\/a><u>. \u0421\u043f\u0430\u0441\u0438\u0431\u043e, <\/u><a href=\"\/ru\/users\/DanyByLuckyCraft\/\" rel=\"noopener noreferrer nofollow\">DanyByLuckyCraft<\/a>!<\/p>\n<p>\u0418 \u0442\u0430\u043a, \u043f\u0438\u0448\u0435\u043c \u0447\u0435\u0440\u0435\u0437 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435:<\/p>\n<pre><code class=\"python\">isCall = False  @bot.callback_query_handler(func=lambda call:True) def call_repley(call):     global isCall     if call.message and call.data == \"stop\":         isCall = True  @bot.message_handler(commands=[\"habr\"]) def habr(message):     global isCall<\/code><\/pre>\n<p>\u0418\u00a0\u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c\u00a0\u0441\u043e\u0431\u044b\u0442\u0438\u0435\u00a0\u0432\u00a0\u201chabr\u201d:<\/p>\n<pre><code class=\"python\">if isCall:      break<\/code><\/pre>\n<p>\u041a\u0430\u043a \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442:<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/495\/5d7\/80e\/4955d780e3802297c53dd90773e77d10.png\" width=\"451\" height=\"195\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/495\/5d7\/80e\/4955d780e3802297c53dd90773e77d10.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0414\u0432\u0438\u0433\u0430\u0435\u043c \u0434\u0430\u043b\u044c\u0448\u0435.<\/p>\n<p>\u00a0<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0434\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0449\u0451 \u043e\u0434\u043d\u0443 \u043a\u043d\u043e\u043f\u043a\u0443, \u0447\u0442\u043e\u0431\u044b \u043b\u0438\u0441\u0442\u0430\u0442\u044c \u0432\u043f\u0435\u0440\u0435\u0434. \u0421\u043c\u043e\u0442\u0440\u044f \u043d\u0430 <a href=\"https:\/\/habr.com\/ru\/post\/675404\/\" rel=\"noopener noreferrer nofollow\"><u>\u0442\u0443-\u0436\u0435 \u0441\u0442\u0430\u0442\u044c\u044e<\/u><\/a>, \u044f \u043e\u0441\u043e\u0437\u043d\u0430\u043b, \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e\u00a0<strong>\u043f\u0435\u0440\u0435\u043b\u0438\u0441\u0442\u044b\u0432\u0430\u0442\u044c<\/strong>\u00a0\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b, \u0432\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u0441\u044b\u043b\u0430\u0442\u044c \u0438\u0445 \u043f\u043e\u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e. \u0415\u0441\u043b\u0438 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0435\u0440\u0435\u043b\u0438\u0441\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b, \u043c\u043e\u0436\u043d\u043e \u043a\u043d\u043e\u043f\u043a\u0443 \u201cSTOP\u00a0IT!\u201d \u0443\u0431\u0440\u0430\u0442\u044c. \u0418 \u0435\u0441\u043b\u0438 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0435\u0440\u0435\u043b\u0438\u0441\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b, \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0435 \u0441\u0442\u0430\u0442\u044c\u0438. \u041d\u0430\u0434\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a\u043d\u043e\u043f\u043a\u0443 \u201c\u043d\u0430\u0437\u0430\u0434\u201d.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u201chabr\u201d \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u0435\u0440\u0435\u0434\u0435\u043b\u044b\u0432\u0430\u0435\u0442\u0441\u044f:<\/p>\n<pre><code class=\"python\">@bot.message_handler(commands=[\"habr\"]) def habr(message):     global page     global pages     page = 0     pages = []     response = requests.get(url2)     response.raise_for_status()     soup = BeautifulSoup(response.text, \"lxml\")     tag2 = soup.find_all(\"article\", class_=\"tm-articles-list__item\")     for i in range(0, 10):         out = tag2[i].find(\"h2\").find(\"span\").text         urlOut = \"https:\/\/habr.com\" + tag2[i].find(\"h2\").find(\"a\").get(\"href\")         pages.append([out, urlOut])     markup = markUP(pages=pages, page=page)     bot.send_message(message.chat.id, pages[page][0], reply_markup=markup)<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0431\u044a\u044f\u0441\u043d\u044e. \u042f \u0441\u043e\u0437\u0434\u0430\u043b \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u201cpages\u201d \u0438 \u201cpage\u201d, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0442\u044b\u0432\u0435\u0447\u0430\u044e\u0442 \u0437\u0430 \u043f\u0435\u0440\u0435\u043b\u0438\u0441\u0442\u044b\u0432\u0430\u043d\u0438\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446. \u0412 (\u0443\u0436\u0435 \u0441\u043f\u0438\u0441\u043e\u043a) \u201cpages\u201d \u043a\u0430\u0436\u0434\u0443\u044e \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044e \u044f \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e \u0435\u0449\u0435 \u0441\u043f\u0438\u0441\u043e\u043a \u0438\u0437 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445\u00a0out\u00a0\u0438\u00a0urlOut. \u0418 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u201cpage\u201d \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0438\u043d\u0434\u0435\u043a\u0441 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 [out,\u00a0urlOut] \u0432 \u201cpages\u201d.<\/p>\n<p>\u0412 \u043a\u043e\u0434\u0435 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c \u0441\u0442\u0440\u043e\u0447\u043a\u0443<\/p>\n<pre><code class=\"python\">markup = markUP(pages=pages, page=page)<\/code><\/pre>\n<p>\u041e\u043d\u0430 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u201cmarkup\u201d \u043d\u0435\u043a\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u201cmarkUP\u201d. \u042f \u0441\u0434\u0435\u043b\u0430\u043b \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u201cmarkUP\u201d:<\/p>\n<pre><code class=\"python\">def markUP(pages, page):     markup = types.InlineKeyboardMarkup(row_width=2)     btn_url = types.InlineKeyboardButton(text=\"Go to habr.\", url=pages[page][1])     btn_next = types.InlineKeyboardButton(text=\"Next page.\", callback_data=\"habr_next\")     btn_back = types.InlineKeyboardButton(text=\"Back page.\", callback_data=\"habr_back\")     markup.add(btn_back, btn_next, btn_url)     return markup<\/code><\/pre>\n<p>\u042f \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0437\u044f\u043b \u044d\u0442\u0438 \u0441\u0442\u043e\u0447\u043a\u0438<\/p>\n<pre><code class=\"python\">markup = types.InlineKeyboardMarkup(row_width=2) btn_url = types.InlineKeyboardButton(text=\"Go to habr.\", url=urlOut) btn_stop = types.InlineKeyboardButton(text=\"STOP IT!\", callback_data=\"stop_news\") markup.add(btn_url, btn_stop)<\/code><\/pre>\n<p>\u0438 \u043f\u0435\u0440\u0435\u043d\u0435\u0441 \u0438\u0445 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0442\u044c \u0438\u0445 4 \u0440\u0430\u0437\u0430.<\/p>\n<p>call_reply\u00a0\u0442\u043e\u0436\u0435 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043f\u0435\u0440\u0435\u0434\u0435\u043b\u0430\u0442\u044c:<\/p>\n<pre><code class=\"python\">@bot.callback_query_handler(func=lambda call:True) def call_repley(call):     global page     global pages     if call.message and call.data == \"habr_back\":         page -= 1         try:             markup = markUP(pages=pages, page=page)             bot.edit_message_text(pages[page][0], reply_markup = markup, chat_id=call.message.chat.id, message_id=call.message.message_id)         except:             bot.answer_callback_query(call.id, show_alert=True, text=\"\u0422\u0430\u043a\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043d\u0435\u0442\u0443.\")             page += 1     if call.message and call.data == \"habr_next\":         page += 1         try:             markup = markUP(pages=pages, page=page)             bot.edit_message_text(pages[page][0], reply_markup = markup, chat_id=call.message.chat.id, message_id=call.message.message_id)         except:             bot.answer_callback_query(call.id, show_alert=True, text=\"\u0422\u0430\u043a\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043d\u0435\u0442\u0443.\")             page -= 1<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043d\u0430\u0436\u0430\u0442\u0438\u044f \u043a\u043d\u043e\u043f\u043a\u0438, \u043f\u0435\u0440\u0432\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0438 \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0434\u0440\u0443\u0433\u0438\u043c, \u0441 \u0434\u0440\u0443\u0433\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u201cpage\u201d \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 [out,\u00a0urlOut]. \u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f\u00a0try-except\u00a0\u043d\u0443\u0436\u043d\u0430, \u0447\u0442\u043e\u0431\u044b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u00a0page\u00a0\u043d\u0435 \u0432\u044b\u0448\u043b\u043e \u0437\u0430 \u0440\u0430\u043c\u043a\u0438 \u201cpages\u201d(\u043a\u043e\u0440\u043e\u0447\u0435, \u0447\u0442\u043e\u0431\u044b \u043e\u0448\u0438\u0431\u043a\u0430 \u201cIndexError:\u00a0list\u00a0index\u00a0out\u00a0of\u00a0range\u201d \u043d\u0435 \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c).\u00a0<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u043f\u0440\u043e \u201chabrNews\u201d:<\/p>\n<pre><code class=\"python\">@bot.message_handler(commands=[\"news\"]) def habrNews(message):     global page     global pages     page = 0     pages = []     response2 = requests.get(url)     response2.raise_for_status()     soup2 = BeautifulSoup(response2.text, \"lxml\")     tag = soup2.find_all(\"article\", class_=\"tm-articles-list__item\")     for i in range(0, 10):         out = tag[i].find(\"h2\").find(\"span\").text         urlOut = \"https:\/\/habr.com\" + tag[i].find(\"h2\").find(\"a\").get(\"href\")         pages.append([out, urlOut])     markup = markUP(pages=pages, page=page)     bot.send_message(message.chat.id, pages[page][0], reply_markup=markup)<\/code><\/pre>\n<p>\u041d\u0443 \u0432\u043e\u0442 \u0438 \u0432\u0441\u0451!<\/p>\n<p>\u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"python\">from re import T import requests from bs4 import BeautifulSoup import telebot from telebot import types  bot = telebot.TeleBot(\"TOKEN\") url = \"https:\/\/habr.com\/ru\/news\/\" url2 = \"https:\/\/habr.com\/ru\/all\/\"  response = requests.get(url) response.raise_for_status()  response2 = requests.get(url2) response2.raise_for_status()  soup = BeautifulSoup(response.text, \"lxml\") tag2 = soup.find_all(\"article\", class_=\"tm-articles-list__item\")  soup2 = BeautifulSoup(response2.text, \"lxml\") tag = soup2.find_all(\"article\", class_=\"tm-articles-list__item\")  @bot.message_handler(commands=[\"start\"]) def start(m, res=False):     bot.send_message(m.chat.id, \"Bot is started.\")  page = 0 pages = []  def markUP(pages, page):     markup = types.InlineKeyboardMarkup(row_width=2)     btn_url = types.InlineKeyboardButton(text=\"Go to habr.\", url=pages[page][1])     btn_next = types.InlineKeyboardButton(text=\"Next page.\", callback_data=\"habr_next\")     btn_back = types.InlineKeyboardButton(text=\"Back page.\", callback_data=\"habr_back\")     markup.add(btn_back, btn_next, btn_url)     return markup  @bot.callback_query_handler(func=lambda call:True) def call_repley(call):     global page     global pages     if call.message and call.data == \"habr_back\":         page -= 1         try:             markup = markUP(pages=pages, page=page)             bot.edit_message_text(pages[page][0], reply_markup = markup, chat_id=call.message.chat.id, message_id=call.message.message_id)         except:             bot.answer_callback_query(call.id, show_alert=True, text=\"\u0422\u0430\u043a\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043d\u0435\u0442\u0443.\")             page += 1     if call.message and call.data == \"habr_next\":         page += 1         try:             markup = markUP(pages=pages, page=page)             bot.edit_message_text(pages[page][0], reply_markup = markup, chat_id=call.message.chat.id, message_id=call.message.message_id)         except:             bot.answer_callback_query(call.id, show_alert=True, text=\"\u0422\u0430\u043a\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043d\u0435\u0442\u0443.\")             page -= 1  @bot.message_handler(commands=[\"habr\"]) def habr(message):     global page     global pages     page = 0     pages = []     response = requests.get(url2)     response.raise_for_status()     soup = BeautifulSoup(response.text, \"lxml\")     tag2 = soup.find_all(\"article\", class_=\"tm-articles-list__item\")     for i in range(0, 10):         out = tag2[i].find(\"h2\").find(\"span\").text         urlOut = \"https:\/\/habr.com\" + tag2[i].find(\"h2\").find(\"a\").get(\"href\")         pages.append([out, urlOut])     markup = markUP(pages=pages, page=page)     bot.send_message(message.chat.id, pages[page][0], reply_markup=markup)  @bot.message_handler(commands=[\"news\"]) def habrNews(message):     global page     global pages     page = 0     pages = []     response2 = requests.get(url)     response2.raise_for_status()     soup2 = BeautifulSoup(response2.text, \"lxml\")     tag = soup2.find_all(\"article\", class_=\"tm-articles-list__item\")     for i in range(0, 10):         out = tag[i].find(\"h2\").find(\"span\").text         urlOut = \"https:\/\/habr.com\" + tag[i].find(\"h2\").find(\"a\").get(\"href\")         pages.append([out, urlOut])     markup = markUP(pages=pages, page=page)     bot.send_message(message.chat.id, pages[page][0], reply_markup=markup)  bot.polling(none_stop=True, interval=0) <\/code><\/pre>\n<p>\u0412\u0435\u0441\u044c \u043a\u043e\u0434 \u0442\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 <a href=\"https:\/\/github.com\/daniil12332\/telebot.git\" rel=\"noopener noreferrer nofollow\">github\u0415<\/a>.<\/p>\n<p>\u042f \u0437\u0430\u0431\u044b\u043b \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u043a\u0430\u043a \u044d\u0442\u043e\u0433\u043e \u0431\u043e\u0442\u0430 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437\u00a0fatherBot, \u043d\u043e \u044d\u0442\u043e \u0438 \u0442\u0430\u043a \u0432\u0441\u0435 \u0437\u043d\u0430\u044e\u0442.<\/p>\n<p>\u041a\u0430\u043a \u044f \u0443\u0436\u0435 \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u043b, \u043c\u043d\u0435 12 \u043b\u0435\u0442. \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0431\u043e\u0442\u043e\u0432 \u043c\u043e\u0433\u0443\u0442 \u0432\u0441\u0435!\u00a0<\/p>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0437\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435!<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/686174\/\"> https:\/\/habr.com\/ru\/post\/686174\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041a\u0430\u0436\u0434\u044b\u0439 \u0434\u0435\u043d\u044c \u043c\u044b \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c\u00a0habr. \u041a\u0430\u0436\u0434\u044b\u0439 \u0434\u0435\u043d\u044c \u0437\u0430\u0445\u043e\u0434\u0438\u043c \u043d\u0430 \u0433\u043b\u0430\u0432\u043d\u0443\u044e \u043b\u0435\u043d\u0442\u0443 \u0438 \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c \u0435\u0451. \u0427\u0442\u043e, \u0435\u0441\u043b\u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440?<\/p>\n<p>\u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u044f \u043f\u0438\u0441\u0430\u043b\u00a0telegram-\u0431\u043e\u0442\u0430 \u043d\u0430\u00a0python3, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0442\u0430\u0441\u043a\u0438\u0432\u0430\u0435\u0442 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u0441\u0442\u0430\u0442\u0435\u0439 \u0441 <a href=\"https:\/\/habr.com\/ru\/all\/\" rel=\"noopener noreferrer nofollow\">habr<\/a> \u0438 \u043f\u0438\u0448\u0435\u0442 \u0438\u0445 \u0432\u00a0telegram.<\/p>\n<h2>\u041a\u0430\u043a \u044d\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c?<\/h2>\n<p>\u0423\u00a0python3 \u0435\u0441\u0442\u044c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u2013\u00a0beautiful\u00a0soap\u00a04. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u044d\u0442\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043c\u043e\u0436\u043d\u043e\u00a0<strong>\u043f\u0430\u0440\u0441\u0438\u0442\u044c<\/strong>\u00a0\u0441\u0430\u0439\u0442\u044b.\u00a0<\/p>\n<p>\u041f\u0430\u0440\u0441\u0438\u043d\u0433 (parsing) \u2014 \u044d\u0442\u043e\u00a0<strong>\u0441\u0431\u043e\u0440 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0438\u0437 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0438\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432 \u0438 \u0441\u0430\u0439\u0442\u043e\u0432 \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0446\u0435\u043b\u044f\u0445, \u043e\u0442 \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0438 \u0434\u043e \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/strong>, \u043f\u0440\u043e\u0441\u0442\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u044d\u0442\u043e \u0441\u0431\u043e\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432.<\/p>\n<p>\u041f\u0440\u043e\u0441\u0442\u044b\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u044f \u043f\u0438\u0448\u0443 \u0441\u043a\u0440\u0438\u043f\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0442\u0430\u0441\u043a\u0438\u0432\u0430\u0435\u0442 \u0438\u0437 \u0441\u0430\u0439\u0442\u0430 \u043a\u0430\u043a\u0443\u044e-\u0442\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e (\u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u0441\u0442\u0430\u0442\u0435\u0439). \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0435 \u0441\u0430\u0439\u0442\u043e\u0432 \u00a0<a href=\"https:\/\/dvmn.org\/encyclopedia\/modules\/bs4-tutorial\/\" rel=\"noopener noreferrer nofollow\"><u>\u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0437\u0434\u0435\u0441\u044c<\/u><\/a><u>.<\/u><\/p>\n<p>\u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0432\u0438\u0434\u0435\u0442\u044c \u043f\u043e \u201c\u044d\u0442\u043e\u043c\u0443\u201d \u0441\u043a\u0440\u0438\u043d\u0443,\u00a0<\/p>\n<figure class=\"float bordered\"><figcaption>&#171;\u044d\u0442\u043e\u0442&#187; \u0441\u043a\u0440\u0438\u043d<\/figcaption><\/figure>\n<p>\u041a\u0430\u0436\u0434\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u0432 \u0445\u0430\u0431\u0440\u0435 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0442\u044d\u0433\u043e\u0432 \u201c\u00a0article\u201d\u00a0\u00a0\u0441\u043e \u0441\u0432\u043e\u0438\u043c\u00a0id.<\/p>\n<p>\u00a0<\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e, \u043f\u043e\u043a\u0430 \u043e\u043d\u0430 \u043d\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u0442 \u0441\u00a0id. \u042d\u0442\u043e\u0442 \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u0447\u0435\u043d\u044c \u0434\u043e\u043b\u0433\u0438\u0439. \u041d\u0430\u0434\u043e \u0436\u0434\u0430\u0442\u044c, \u043f\u043e\u043a\u0430\u00a0python3 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442 ~700\u00a0000 \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439!\u00a0<\/p>\n<p>\u0415\u0441\u0442\u044c \u0434\u0440\u0443\u0433\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442. \u041c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432\u0441\u0435 \u0442\u044d\u0433\u0438 \u201c\u00a0article\u201d, \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0438\u0435 \u0437\u0430 \u0441\u0442\u0430\u0442\u044c\u0438, \u0438 \u043f\u043e\u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u043f\u0435\u0440\u0435\u0431\u0438\u0440\u0430\u0442\u044c \u044d\u0442\u0438 \u0442\u044d\u0433\u0438. \u0426\u0438\u043a\u043b \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f, \u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0434\u0435\u043b\u0430\u0442\u044c \u0443\u0436\u0435 20(\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u0430\u0442\u0435\u0439 \u043d\u0430 \u0433\u043b\u0430\u0432. \u044d\u043a\u0440\u0430\u043d\u0435) \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u0439.<\/p>\n<pre><code class=\"python\">from itertools import count from re import I import requests from bs4 import BeautifulSoup  url2 = \"https:\/\/habr.com\/ru\/all\/\" response2 = requests.get(url2) response2.raise_for_status()  soup2 = BeautifulSoup(response2.text, \"lxml\") tag = soup2.find_all(\"article\", class_=\"tm-articles-list__item\")  for i in range(0, 10):     out = tag[i].find(\"h2\").find(\"span\").text     print(out + \" url: \" + \"https:\/\/habr.com\" + urlOut)<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438\u043a\u043b\u0435\u0435\u0432\u044b\u0435\u043c \u044d\u0442\u043e\u0442 \u043a\u0443\u0441\u043e\u043a \u043a\u043e\u0434\u0430 \u043a\u00a0pyTelegramBotAPI:<\/p>\n<pre><code class=\"python\">import requests from bs4 import BeautifulSoup import telebot  bot = telebot.TeleBot(\"TOKEN\")  url2 = \"https:\/\/habr.com\/ru\/all\/\" response2 = requests.get(url2) response2.raise_for_status()  soup2 = BeautifulSoup(response2.text, \"lxml\") tag = soup2.find_all(\"article\", class_=\"tm-articles-list__item\")  @bot.message_handler(commands=[\"start\"]) def start(m, res=False):     bot.send_message(m.chat.id, \"Bot is started.\")  @bot.message_handler(commands=[\"habr\"]) def habr(message):     global url2     response2 = requests.get(url2)     response2.raise_for_status()      soup2 = BeautifulSoup(response2.text, \"lxml\")     tag = soup2.find_all(\"article\", class_=\"tm-articles-list__item\")     for i in range(0, 10):         out = tag[i].find(\"h2\").find(\"span\").text         bot.send_message(message.chat.id, out)  bot.polling(none_stop=True, interval=0)<\/code><\/pre>\n<p>\u041e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u043d\u043e \u043f\u0440\u0438\u043a\u0440\u0435\u043f\u0438\u0442\u044c \u044d\u0442\u0438 \u0441\u0442\u0440\u043e\u0447\u043a\u0438 \u0432 \u0444\u0443\u043d\u0446\u0438\u044e\u00a0habr, \u0442.\u043a. \u0435\u0441\u043b\u0438 \u044d\u0442\u043e\u0433\u043e \u043d\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u043d\u0430\u0448 \u0431\u043e\u0442 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u0441\u044f.<\/p>\n<p>\u042d\u0442\u0438\u00a0\u0441\u0442\u0440\u043e\u0447\u043a\u0438:<\/p>\n<pre><code class=\"python\">response2 = requests.get(url2) response2.raise_for_status()  soup2 = BeautifulSoup(response2.text, \"lxml\") tag = soup2.find_all(\"article\", class_=\"tm-articles-list__item\")<\/code><\/pre>\n<p>\u042d\u0442\u043e \u043f\u043e\u043a\u0430 \u043d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u0443\u0434\u043e\u0431\u043d\u043e! \u0421\u0441\u044b\u043b\u043a\u0438-\u0442\u043e \u043d\u0435\u0442\u0443!\u00a0<\/p>\n<p>\u041f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0441\u043e \u0441\u0441\u044b\u043b\u043a\u043e\u0439 \u043b\u0435\u0433\u043a\u043e \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c. \u041d\u0430\u0434\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u0443 \u0441\u0442\u0440\u043e\u0447\u043a\u0443 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e\u00a0\u201chabr\u201d:<\/p>\n<pre><code class=\"python\">urlOut = \"https:\/\/habr.com\" + tag[i].find(\"h2\").find(\"a\").get(\"href\")<\/code><\/pre>\n<p>\u0418 \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0432\u044b\u0432\u043e\u0434 \u0441 &#171;out&#187; \u043d\u0430 &#171;out\u00a0+\u00a0&#187; url: &#187;\u00a0+\u00a0urlOut&#187;.<\/p>\n<p>\u0412\u043e\u0442,\u00a0\u00a0\u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0432\u00a0telegram:<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u0412\u044b\u0432\u043e\u0434 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0440\u0435\u0437\u043a\u0438\u0439 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f. \u041d\u0430\u0434\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0443 \u043c\u0435\u0436\u0434\u0443 \u043a\u0430\u0436\u0434\u044b\u043c \u0432\u044b\u0432\u043e\u0434\u043e\u043c.<\/p>\n<p>\u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c\u00a0sleep\u00a0\u0438\u0437\u00a0time:<\/p>\n<pre><code class=\"python\">from time import sleep<\/code><\/pre>\n<p>\u0418 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0443 \u0432 \u0446\u0438\u043a\u043b:<\/p>\n<pre><code class=\"python\">for i in range(0, 10):         out = tag[i].find(\"h2\").find(\"span\").text         urlOut = \"https:\/\/habr.com\" + tag[i].find(\"h2\").find(\"a\").get(\"href\")         bot.send_message(message.chat.id, out + \"url: \" + urlOut)         sleep(5)<\/code><\/pre>\n<p>\u0412\u00a0telegram\u00a0\u0432\u0441\u0451 \u0442\u043e\u0436\u0435-\u0441\u0430\u043c\u043e\u0435, \u043d\u043e \u043c\u0435\u0436\u0434\u0443 \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435\u0439 \u2013 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0430.<\/p>\n<p>\u0418 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u043e\u0432\u043e\u0441\u0442\u0438:<\/p>\n<pre><code class=\"python\">@bot.message_handler(commands=[\"news\"]) def habr(message):     global url     response2 = requests.get(url)     response2.raise_for_status()      soup2 = BeautifulSoup(response2.text, \"lxml\")     tag = soup2.find_all(\"article\", class_=\"tm-articles-list__item\")     for i in range(0, 10):         out = tag[i].find(\"h2\").find(\"span\").text         urlOut = \"https:\/\/habr.com\" + tag[i].find(\"h2\").find(\"a\").get(\"href\")         bot.send_message(message.chat.id, out + \"url: \" + urlOut)         sleep(5)<\/code><\/pre>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u0417\u043d\u0430\u0435\u0442\u0435, \u0447\u0442\u043e \u044f \u0432\u0430\u043c \u0441\u043a\u0430\u0436\u0443? \u042d\u0442\u043e \u043e\u043f\u044f\u0442\u044c \u043d\u0435\u0443\u0434\u043e\u0431\u043d\u043e! \u0410 \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u044f \u043d\u0435 \u0437\u0430\u0445\u043e\u0447\u0443 \u0447\u0438\u0442\u0430\u0442\u044c \u0434\u0430\u043b\u044c\u0448\u0435? \u041d\u0443\u0436\u043d\u0430 \u043a\u043d\u043e\u043f\u043a\u0430, \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0430\u044f \u0437\u0430 \u0441\u0442\u043e\u043f. \u041f\u043e\u0438\u0437\u0443\u0447\u0430\u0432, \u043a\u0430\u043a \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442, \u044f \u043d\u0430\u0448\u0435\u043b \u0438\u00a0url-\u043a\u043d\u043e\u043f\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u043d\u0430 \u0441\u0430\u0439\u0442. \u041e\u0442\u0434\u0435\u043b\u044c\u043d\u0430\u044f \u043a\u043d\u043e\u043f\u043a\u0430 \u043a\u0440\u0430\u0441\u0438\u0432\u0435\u0435, \u0447\u0435\u043c \u0442\u0443\u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0430! \u041a\u043e\u0440\u043e\u0447\u0435, \u0434\u0435\u043b\u0430\u0435\u043c \u0434\u0432\u0435\u00a0Inline\u00a0\u043a\u043d\u043e\u043f\u043a\u0438.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u043e \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u201chabr\u201d \u0438 \u201cnews\u201d \u044d\u0442\u0438 \u0441\u0442\u0440\u043e\u043a\u0438:<\/p>\n<pre><code class=\"python\">markup = types.InlineKeyboardMarkup(row_width=2) btn_url = types.InlineKeyboardButton(text=\"Go to habr.\", url=urlOut) btn_stop = types.InlineKeyboardButton(text=\"STOP IT!\", callback_data=\"stop\") markup.add(btn_url, btn_stop)<\/code><\/pre>\n<p>\u0438\u00a0\u0434\u043b\u044f\u00a0\u201chabrNews\u201d :<\/p>\n<pre><code class=\"python\">markup = types.InlineKeyboardMarkup(row_width=2) btn_url = types.InlineKeyboardButton(text=\"Go to habr.\", url=urlOut) btn_stop = types.InlineKeyboardButton(text=\"STOP IT!\", callback_data=\"stop_news\") markup.add(btn_url, btn_stop)<\/code><\/pre>\n<p>\u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0432\u00a0bot.send_message. \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"python\">bot.send_message(message.chat.id, out + \"url: \" + urlOut, reply_markup=markup)<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0441\u043e\u0431\u044b\u0442\u0438\u044f\u00a0callback\u00a0\u043a\u043d\u043e\u043f\u043a\u0438:<\/p>\n<pre><code class=\"python\">@bot.callback_query_handler(func=lambda call:True) def call_repley(call):     if call.message and call.data == \"stop\":         None<\/code><\/pre>\n<p>\u0418 \u0432\u043e\u0442 \u0442\u0443\u0442 \u044f \u043f\u0440\u044f\u043c \u0432\u0441\u0442\u0430\u043b. \u042f \u043d\u0435 \u0437\u043d\u0430\u043b, \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c! \u041c\u043d\u0435 \u043d\u0430\u0434\u043e \u0431\u044b\u043b\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0438\u0437 \u201ccall_repley\u201d \u0432 \u201chabr\u201d. \u0412\u00a0habr\u0415 \u0443\u043c\u043d\u044b\u0435 \u0434\u044f\u0434\u044c\u043a\u0438 \u043f\u0438\u0448\u0443\u0442, \u0447\u0442\u043e \u043b\u0443\u0447\u0448\u0438\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u044d\u0442\u043e \u0447\u0435\u0440\u0435\u0437\u00a0callback_data, \u043d\u043e \u044f 12-\u0442\u0438 \u043b\u0435\u0442\u043d\u0438\u0439 \u043f\u0430\u0446\u0430\u043d! \u041c\u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0441\u043b\u043e\u0436\u043d\u044b\u043c \u044d\u0442\u0430 \u0441\u0445\u0435\u043c\u0430. \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c,\u00a0\u00a0\u0447\u0442\u043e \u0443\u043c\u043d\u044b\u0435 \u0434\u044f\u0434\u044c\u043a\u0438 \u0438\u0437\u00a0habr\u0410 \u043f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c, \u043a\u0430\u043a \u043f\u0438\u0448\u0443\u0442 \u0447\u0435\u0440\u0435\u0437\u00a0callback_data, \u043f\u0438\u0448\u0443\u0442 \u0447\u0435\u0440\u0435\u0437 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435. \u042f \u043d\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u043b, \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0433\u043b\u0430\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0434\u043e \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u043b\u00a0<a href=\"https:\/\/habr.com\/ru\/post\/675404\/\" rel=\"noopener noreferrer nofollow\">\u044d\u0442\u0443 \u0441\u0442\u0430\u0442\u044c\u044e<\/a><u>. \u0421\u043f\u0430\u0441\u0438\u0431\u043e, <\/u><a href=\"\/ru\/users\/DanyByLuckyCraft\/\" rel=\"noopener noreferrer nofollow\">DanyByLuckyCraft<\/a>!<\/p>\n<p>\u0418 \u0442\u0430\u043a, \u043f\u0438\u0448\u0435\u043c \u0447\u0435\u0440\u0435\u0437 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435:<\/p>\n<pre><code class=\"python\">isCall = False  @bot.callback_query_handler(func=lambda call:True) def call_repley(call):     global isCall     if call.message and call.data == \"stop\":         isCall = True  @bot.message_handler(commands=[\"habr\"]) def habr(message):     global isCall<\/code><\/pre>\n<p>\u0418\u00a0\u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c\u00a0\u0441\u043e\u0431\u044b\u0442\u0438\u0435\u00a0\u0432\u00a0\u201chabr\u201d:<\/p>\n<pre><code class=\"python\">if isCall:      break<\/code><\/pre>\n<p>\u041a\u0430\u043a \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442:<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u0414\u0432\u0438\u0433\u0430\u0435\u043c \u0434\u0430\u043b\u044c\u0448\u0435.<\/p>\n<p>\u00a0<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0434\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0435\u0449\u0451 \u043e\u0434\u043d\u0443 \u043a\u043d\u043e\u043f\u043a\u0443, \u0447\u0442\u043e\u0431\u044b \u043b\u0438\u0441\u0442\u0430\u0442\u044c \u0432\u043f\u0435\u0440\u0435\u0434. \u0421\u043c\u043e\u0442\u0440\u044f \u043d\u0430 <a href=\"https:\/\/habr.com\/ru\/post\/675404\/\" rel=\"noopener noreferrer nofollow\"><u>\u0442\u0443-\u0436\u0435 \u0441\u0442\u0430\u0442\u044c\u044e<\/u><\/a>, \u044f \u043e\u0441\u043e\u0437\u043d\u0430\u043b, \u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e\u00a0<strong>\u043f\u0435\u0440\u0435\u043b\u0438\u0441\u0442\u044b\u0432\u0430\u0442\u044c<\/strong>\u00a0\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b, \u0432\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u0441\u044b\u043b\u0430\u0442\u044c \u0438\u0445 \u043f\u043e\u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e. \u0415\u0441\u043b\u0438 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0435\u0440\u0435\u043b\u0438\u0441\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b, \u043c\u043e\u0436\u043d\u043e \u043a\u043d\u043e\u043f\u043a\u0443 \u201cSTOP\u00a0IT!\u201d \u0443\u0431\u0440\u0430\u0442\u044c. \u0418 \u0435\u0441\u043b\u0438 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u0435\u0440\u0435\u043b\u0438\u0441\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b, \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0435 \u0441\u0442\u0430\u0442\u044c\u0438. \u041d\u0430\u0434\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043a\u043d\u043e\u043f\u043a\u0443 \u201c\u043d\u0430\u0437\u0430\u0434\u201d.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u201chabr\u201d \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u0435\u0440\u0435\u0434\u0435\u043b\u044b\u0432\u0430\u0435\u0442\u0441\u044f:<\/p>\n<pre><code class=\"python\">@bot.message_handler(commands=[\"habr\"]) def habr(message):     global page     global pages     page = 0     pages = []     response = requests.get(url2)     response.raise_for_status()     soup = BeautifulSoup(response.text, \"lxml\")     tag2 = soup.find_all(\"article\", class_=\"tm-articles-list__item\")     for i in range(0, 10):         out = tag2[i].find(\"h2\").find(\"span\").text         urlOut = \"https:\/\/habr.com\" + tag2[i].find(\"h2\").find(\"a\").get(\"href\")         pages.append([out, urlOut])     markup = markUP(pages=pages, page=page)     bot.send_message(message.chat.id, pages[page][0], reply_markup=markup)<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0431\u044a\u044f\u0441\u043d\u044e. \u042f \u0441\u043e\u0437\u0434\u0430\u043b \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u201cpages\u201d \u0438 \u201cpage\u201d, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0442\u044b\u0432\u0435\u0447\u0430\u044e\u0442 \u0437\u0430 \u043f\u0435\u0440\u0435\u043b\u0438\u0441\u0442\u044b\u0432\u0430\u043d\u0438\u0435 \u0441\u0442\u0440\u0430\u043d\u0438\u0446. \u0412 (\u0443\u0436\u0435 \u0441\u043f\u0438\u0441\u043e\u043a) \u201cpages\u201d \u043a\u0430\u0436\u0434\u0443\u044e \u0438\u0442\u0435\u0440\u0430\u0446\u0438\u044e \u044f \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e \u0435\u0449\u0435 \u0441\u043f\u0438\u0441\u043e\u043a \u0438\u0437 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445\u00a0out\u00a0\u0438\u00a0urlOut. \u0418 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u201cpage\u201d \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0438\u043d\u0434\u0435\u043a\u0441 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 [out,\u00a0urlOut] \u0432 \u201cpages\u201d.<\/p>\n<p>\u0412 \u043a\u043e\u0434\u0435 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c \u0441\u0442\u0440\u043e\u0447\u043a\u0443<\/p>\n<pre><code class=\"python\">markup = markUP(pages=pages, page=page)<\/code><\/pre>\n<p>\u041e\u043d\u0430 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u043f\u0440\u0438\u0441\u0432\u043e\u0435\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u201cmarkup\u201d \u043d\u0435\u043a\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u201cmarkUP\u201d. \u042f \u0441\u0434\u0435\u043b\u0430\u043b \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u201cmarkUP\u201d:<\/p>\n<pre><code class=\"python\">def markUP(pages, page):     markup = types.InlineKeyboardMarkup(row_width=2)     btn_url = types.InlineKeyboardButton(text=\"Go to habr.\", url=pages[page][1])     btn_next = types.InlineKeyboardButton(text=\"Next page.\", callback_data=\"habr_next\")     btn_back = types.InlineKeyboardButton(text=\"Back page.\", callback_data=\"habr_back\")     markup.add(btn_back, btn_next, btn_url)     return markup<\/code><\/pre>\n<p>\u042f \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0437\u044f\u043b \u044d\u0442\u0438 \u0441\u0442\u043e\u0447\u043a\u0438<\/p>\n<pre><code class=\"python\">markup = types.InlineKeyboardMarkup(row_width=2) btn_url = types.InlineKeyboardButton(text=\"Go to habr.\", url=urlOut) btn_stop = types.InlineKeyboardButton(text=\"STOP IT!\", callback_data=\"stop_news\") markup.add(btn_url, btn_stop)<\/code><\/pre>\n<p>\u0438 \u043f\u0435\u0440\u0435\u043d\u0435\u0441 \u0438\u0445 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u0442\u044c \u0438\u0445 4 \u0440\u0430\u0437\u0430.<\/p>\n<p>call_reply\u00a0\u0442\u043e\u0436\u0435 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043f\u0435\u0440\u0435\u0434\u0435\u043b\u0430\u0442\u044c:<\/p>\n<pre><code class=\"python\">@bot.callback_query_handler(func=lambda call:True) def call_repley(call):     global page     global pages     if call.message and call.data == \"habr_back\":         page -= 1         try:             markup = markUP(pages=pages, page=page)             bot.edit_message_text(pages[page][0], reply_markup = markup, chat_id=call.message.chat.id, message_id=call.message.message_id)         except:             bot.answer_callback_query(call.id, show_alert=True, text=\"\u0422\u0430\u043a\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043d\u0435\u0442\u0443.\")             page += 1     if call.message and call.data == \"habr_next\":         page += 1         try:             markup = markUP(pages=pages, page=page)             bot.edit_message_text(pages[page][0], reply_markup = markup, chat_id=call.message.chat.id, message_id=call.message.message_id)         except:             bot.answer_callback_query(call.id, show_alert=True, text=\"\u0422\u0430\u043a\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043d\u0435\u0442\u0443.\")             page -= 1<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043d\u0430\u0436\u0430\u0442\u0438\u044f \u043a\u043d\u043e\u043f\u043a\u0438, \u043f\u0435\u0440\u0432\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0438 \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0434\u0440\u0443\u0433\u0438\u043c, \u0441 \u0434\u0440\u0443\u0433\u0438\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u201cpage\u201d \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 [out,\u00a0urlOut]. \u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f\u00a0try-except\u00a0\u043d\u0443\u0436\u043d\u0430, \u0447\u0442\u043e\u0431\u044b \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u00a0page\u00a0\u043d\u0435 \u0432\u044b\u0448\u043b\u043e \u0437\u0430 \u0440\u0430\u043c\u043a\u0438 \u201cpages\u201d(\u043a\u043e\u0440\u043e\u0447\u0435, \u0447\u0442\u043e\u0431\u044b \u043e\u0448\u0438\u0431\u043a\u0430 \u201cIndexError:\u00a0list\u00a0index\u00a0out\u00a0of\u00a0range\u201d \u043d\u0435 \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c).\u00a0<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u043f\u0440\u043e \u201chabrNews\u201d:<\/p>\n<pre><code class=\"python\">@bot.message_handler(commands=[\"news\"]) def habrNews(message):     global page     global pages     page = 0     pages = []     response2 = requests.get(url)     response2.raise_for_status()     soup2 = BeautifulSoup(response2.text, \"lxml\")     tag = soup2.find_all(\"article\", class_=\"tm-articles-list__item\")     for i in range(0, 10):         out = tag[i].find(\"h2\").find(\"span\").text         urlOut = \"https:\/\/habr.com\" + tag[i].find(\"h2\").find(\"a\").get(\"href\")         pages.append([out, urlOut])     markup =<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-337867","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/337867","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=337867"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/337867\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=337867"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=337867"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=337867"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}