{"id":334439,"date":"2022-06-14T09:00:55","date_gmt":"2022-06-14T09:00:55","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=334439"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=334439","title":{"rendered":"<span>Threading. \u0417\u0430\u0447\u0435\u043c?<\/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>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043a\u0430\u043a \u043e\u0434\u0438\u043d \u0438\u0437 \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0440\u0435\u0448\u0430\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0438, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u0432\u0432\u043e\u0434\u043e\u043c-\u0432\u044b\u0432\u043e\u0434\u043e\u043c, \u0438 \u043d\u0430 \u0435\u0433\u043e \u043e\u0441\u043d\u043e\u0432\u0435 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043f\u0430\u0440\u0441\u0435\u0440.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/650\/007\/5a6\/6500075a653cce0baa42c2df8f765b51.png\" width=\"643\" height=\"482\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/650\/007\/5a6\/6500075a653cce0baa42c2df8f765b51.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u0441\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0447\u0430\u0441\u0442\u043e, \u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c \u0444\u0430\u043a\u0442\u043e\u0440\u043e\u043c, \u0432\u043b\u0438\u044f\u044e\u0449\u0438\u043c \u043d\u0430 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0435\u0451 \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u043e\u0431\u044a\u0451\u043c \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u043e\u0440\u043e\u0436\u0434\u0430\u044e\u0449\u0438\u0439 \u0431\u043e\u043b\u044c\u0448\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0439 \u043a \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0443 \u043f\u043e \u0441\u0435\u0442\u0438, \u043f\u0440\u0438\u0447\u0451\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0437\u0430\u0442\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c\u043e\u0433\u043e \u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0441\u0435\u0442\u044c\u044e, \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435 \u043e\u0442\u0432\u0435\u0442\u0430 \u043e\u0442 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430.<\/p>\n<p>\u0423\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u043e\u0442\u0432\u0435\u0442\u0430 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0441\u0435\u0442\u044c\u044e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f, \u043f\u043e\u0434\u0437\u0430\u0434\u0430\u0447\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u043c\u0435\u0436\u0434\u0443 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438.<\/p>\n<p>\u0421\u043e\u0431\u0435\u0440\u0451\u043c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0438\u0445\u043e\u0432 \u043f\u043e\u044d\u0442\u043e\u0432-\u043a\u043b\u0430\u0441\u0441\u0438\u043a\u043e\u0432 \u0438\u0437 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u0433\u043e \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430, \u043e\u0446\u0435\u043d\u0438\u043c \u0437\u0430\u0442\u0440\u0430\u0447\u0435\u043d\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0438 \u0443\u0441\u043a\u043e\u0440\u0438\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u0431\u043e\u0440\u0430. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0443\u0434\u0435\u043c Python, \u043c\u043e\u0434\u0443\u043b\u0438: bs4, json, os, queue, requests, time \u0438 threading.<\/p>\n<p>\u041f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043f\u043e \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u0435 \u0438\u0437 \u043f\u043e\u0438\u0441\u043a\u043e\u0432\u0438\u043a\u0430:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/bf0\/900\/968\/bf09009687b216569b8fed7c3f34aac7.png\" width=\"525\" height=\"209\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/bf0\/900\/968\/bf09009687b216569b8fed7c3f34aac7.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u0432\u0438\u0434\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b, \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u044b\u0432\u043e\u0434 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u043f\u043e \u0430\u0432\u0442\u043e\u0440\u0430\u043c \u043d\u0435\u0442 \u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0430\u0432\u0442\u043e\u0440\u0430 \u043c\u043e\u0433\u0443\u0442 \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u0442\u044c\u0441\u044f \u043a\u0430\u043a \u043d\u0430 \u043f\u0435\u0440\u0432\u043e\u0439, \u0442\u0430\u043a \u0438 \u043d\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430\u0445, \u0443\u0447\u0442\u0451\u043c \u044d\u0442\u043e.<\/p>\n<p>\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430, \u0438\u0434\u0451\u043c \u043d\u0430 \u0432\u043a\u043b\u0430\u0434\u043a\u0443 \u00ab\u0441\u0435\u0442\u044c\u00bb, \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u043b\u044e\u0431\u043e\u0433\u043e \u0430\u0432\u0442\u043e\u0440\u0430:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/349\/1a7\/545\/3491a7545bd03f3809d8cc88b1cd2fd9.png\" width=\"570\" height=\"178\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/349\/1a7\/545\/3491a7545bd03f3809d8cc88b1cd2fd9.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0430\u0448\u043b\u0438 \u0430\u0434\u0440\u0435\u0441, \u043f\u0440\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439, \u0432\u0435\u0440\u043d\u0451\u0442\u0441\u044f json \u0441 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f\u043c\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0430\u0432\u0442\u043e\u0440\u0430.<\/p>\n<p>\u0418\u043c\u043f\u043e\u0440\u0442\u044b:<\/p>\n<pre><code>from bs4 import BeautifulSoup import json import os import requests import time<\/code><\/pre>\n<p>\u0412 \u0440\u0430\u043c\u043a\u0430\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0432\u044b\u0433\u0440\u0443\u0436\u0430\u044e\u0449\u0435\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u0430\u0432\u0442\u043e\u0440\u0443, \u043f\u0440\u043e\u0439\u0434\u0451\u043c \u043f\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c \u0441\u0441\u044b\u043b\u043a\u0430\u043c, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0431\u0440\u0430\u0442\u044c cookie, \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u0434\u043b\u044f \u043c\u043e\u0434\u0443\u043b\u044f requests \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438, \u0431\u0443\u0434\u0435\u043c \u0446\u0438\u043a\u043b\u0438\u0447\u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c json-\u043e\u0442\u0432\u0435\u0442\u044b, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044f \u0438\u0445 \u0432 \u0444\u0430\u0439\u043b:<\/p>\n<pre><code>def getForAuthor(sess, author):     urls = [\"https:\/\/www.google.ru\/\", \"https:\/\/www.youtube.com\/\"]      for i in urls:         sess.get(url=i)      headers = {         \"accept\": \"*\/*\",         \"user-agent\": \"Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/99.0.4844.84 Safari\/537.36\"     }      result = {}     page = 1     while True:         url = f\"https:\/\/www.culture.ru\/_next\/data\/i_YUtTpPEY7K2ap4pw3Y4\/literature\/poems\/{author}.json?pathParams=author-sergei-esenin\"         params = {             \"pathParams\": author,             \"page\": page         }          while True:             try:                 res = sess.get(                     url=url,                     params=params,                     headers=headers                 )                 break             except Exception as ex:                 print(ex)         js = res.json()         maxPage = js[\"pageProps\"][\"pagination\"][\"total\"]         for item in js[\"pageProps\"][\"poems\"]:             result[item[\"_id\"]] = {                 \"id\": item[\"_id\"],                 \"title\": item[\"title\"],                 \"text\": item[\"text\"]             }          if page == maxPage:             break         page += 1              with open(f\".\/data\/{author}.json\", \"w\", encoding=\"utf-8\") as file:         file.write(json.dumps(result, ensure_ascii=False, indent=4))<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c:<\/p>\n<pre><code>if __name__ == \"__main__\":     start = 1     stop = 2     sess = requests.Session()     authors = []     maxPage = int(getMaxPage(sess=sess))     print(maxPage)     start = time.time(      for page in range(start, stop)):         print(page)         url = f\"https:\/\/www.culture.ru\/literature\/poems?page={page}\"          while True:             try:                 res = sess.get(url=url)                 break             except Exception as ex:                 print(ex)          soup = BeautifulSoup(res.text, \"html.parser\")          athrs = soup.find_all(attrs={\"class\": \"_6unAn\"})              for author in athrs:             author = author.get(\"href\").replace(\"\/literature\/poems\/\", \"\")             os.system(\"cls\")                          if author not in authors:                 authors.append(author)             print(len(authors))              for a in authors:         os.system(\"cls\")         print(a)         getForAuthor(sess = sess, author = a)          print(\"Done for\", time.time() - start, \"seconds\", len(authors))<\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0441\u044c:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f51\/8ce\/6bf\/f518ce6bf55f3c74efb366661c96584b.png\" width=\"571\" height=\"346\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f51\/8ce\/6bf\/f518ce6bf55f3c74efb366661c96584b.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0417\u0430\u0433\u043b\u044f\u043d\u0435\u043c \u0432 \u043e\u0434\u0438\u043d \u0438\u0437 \u0444\u0430\u0439\u043b\u043e\u0432, \u0447\u0442\u043e\u0431\u044b \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0432\u0441\u0451 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0442\u0430\u043a, \u043a\u0430\u043a \u043e\u0436\u0438\u0434\u0430\u043b\u043e\u0441\u044c:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/34e\/bd7\/f11\/34ebd7f11c0c8b539b8138a373d95883.png\" width=\"590\" height=\"219\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/34e\/bd7\/f11\/34ebd7f11c0c8b539b8138a373d95883.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c \u0440\u0430\u043d\u0435\u0435, \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u0433\u0440\u0443\u0436\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e \u0448\u0435\u0441\u0442\u043d\u0430\u0434\u0446\u0430\u0442\u0438 \u0430\u0432\u0442\u043e\u0440\u0430\u043c \u0441 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0441\u0430\u0439\u0442\u0430, \u0438 \u044d\u0442\u043e \u0437\u0430\u043d\u044f\u043b\u043e \u043e\u043a\u043e\u043b\u043e \u0441\u0435\u043c\u0438 \u043c\u0438\u043d\u0443\u0442.<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/0d9\/6b3\/1d4\/0d96b31d4fd6447774b6c13c6a95b9d0.png\" width=\"313\" height=\"26\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0d9\/6b3\/1d4\/0d96b31d4fd6447774b6c13c6a95b9d0.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041f\u043e\u0447\u0435\u043c\u0443 \u0442\u0430\u043a \u0434\u043e\u043b\u0433\u043e? \u0418 \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u0440\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043e\u043b\u044c\u0448\u0435 \u0432\u0441\u0435\u0433\u043e? \u041e\u0436\u0438\u0434\u0430\u043d\u0438\u0435.<\/p>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u043c\u043e\u0434\u0443\u043b\u0435\u043c threading: \u0441 \u0435\u0433\u043e \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043f\u043e\u0442\u043e\u043a\u0438, \u0432\u044b\u0433\u0440\u0443\u0436\u0430\u044e\u0449\u0438\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u0430\u0432\u0442\u043e\u0440\u0443 \u0432 \u043e\u0434\u043d\u043e\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435. \u041f\u0440\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f, \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0434\u0440\u0443\u0433\u043e\u0439, \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0432\u0440\u0435\u043c\u044f \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u0441\u044f. \u0414\u043b\u044f \u043e\u0431\u043c\u0435\u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0441 \u043f\u043e\u0442\u043e\u043a\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0438\u0437 \u043c\u043e\u0434\u0443\u043b\u044f queue.<\/p>\n<p>\u0427\u0430\u0441\u0442\u0438\u0447\u043d\u043e \u043f\u0435\u0440\u0435\u043f\u0438\u0448\u0435\u043c \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u0441\u043a\u0440\u0438\u043f\u0442. <\/p>\n<p>\u0418\u043c\u043f\u043e\u0440\u0442\u044b:<\/p>\n<pre><code>from bs4 import BeautifulSoup import json import os from queue import Queue import requests import time import threading<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432 \u043f\u043e\u0442\u043e\u043a\u0435:<\/p>\n<pre><code>def getForAuthor(task):     sess = requests.Session()     urls = [\"https:\/\/www.google.ru\/\", \"https:\/\/www.youtube.com\/\"]     for i in urls:         sess.get(url=i)      headers = {         \"accept\": \"*\/*\",         \"user-agent\": \"Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/99.0.4844.84 Safari\/537.36\"     }      result = {}     page = 1     if not task.empty():         author = task.get()         page = 1         while True:             url = f\"https:\/\/www.culture.ru\/_next\/data\/i_YUtTpPEY7K2ap4pw3Y4\/literature\/poems\/{author}.json?pathParams=author-sergei-esenin\"             params = {                 \"pathParams\": author,                 \"page\": page             }              while True:                 try:                     res = sess.get(                         url=url,                         params=params,                         headers=headers                     )                     break                 except Exception as ex:                     print(ex)             js = res.json()             maxPage = js[\"pageProps\"][\"pagination\"][\"total\"]             for item in js[\"pageProps\"][\"poems\"]:                 result[item[\"_id\"]] = {                     \"id\": item[\"_id\"],                     \"title\": item[\"title\"],                     \"text\": item[\"text\"]                 }              if page == maxPage:                 break             page += 1                      with open(f\".\/data\/{author}.json\", \"w\", encoding=\"utf-8\") as file:             file.write(json.dumps(result, ensure_ascii=False, indent=4))<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c:<\/p>\n<pre><code>if __name__ == \"__main__\":     start = 1     stop = 2     sess = requests.Session()     authors = []     # \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u043e\u0447\u0435\u0440\u0435\u0434\u0438     task = Queue()     start = time.time()      for page in range(start, stop):         print(page)         url = f\"https:\/\/www.culture.ru\/literature\/poems?page={page}\"          while True:             try:                 res = sess.get(url=url)                 break             except Exception as ex:                 print(ex)          soup = BeautifulSoup(res.text, \"html.parser\")          athrs = soup.find_all(attrs={\"class\": \"_6unAn\"})              for author in athrs:             author = author.get(\"href\").replace(\"\/literature\/poems\/\", \"\")             os.system(\"cls\")                          if author not in authors:                 authors.append(author)     # \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043e\u0447\u0435\u0440\u0435\u0434\u0438         for a in authors:         task.put(a)     # \u0437\u0430\u043f\u0443\u0441\u043a \u043f\u043e\u0442\u043e\u043a\u043e\u0432     for _ in range(len(authors)):         threading.Thread(target=getForAuthor, args=(task,)).start()     # \u0446\u0438\u043a\u043b \u0441 \u0443\u0441\u043b\u043e\u0432\u0438\u0435\u043c \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0430 \u0434\u043b\u044f \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430     while True:         if threading.active_count() == 1:             break         print(\"Threading done for\", time.time() - start, \"seconds\", len(authors))<\/code><\/pre>\n<p>\u0412\u044b\u0432\u043e\u0434 \u043f\u043e \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044e \u0440\u0430\u0431\u043e\u0442\u044b, \u043e\u0434\u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430, \u0442\u0435 \u0436\u0435 \u0448\u0435\u0441\u0442\u043d\u0430\u0434\u0446\u0430\u0442\u044c \u0430\u0432\u0442\u043e\u0440\u043e\u0432:<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/d4c\/86c\/4b1\/d4c86c4b1c06b0ad67c5b90e1d2cd9cc.png\" width=\"402\" height=\"24\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/d4c\/86c\/4b1\/d4c86c4b1c06b0ad67c5b90e1d2cd9cc.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041f\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c \u0434\u0435\u043b\u0430\u0435\u043c \u0432\u044b\u0432\u043e\u0434, \u0447\u0442\u043e \u0434\u043e\u0441\u0442\u0430\u043b\u0438 \u0442\u0435 \u0436\u0435 \u0441\u0430\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u043d\u043e, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c, \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u043b\u0438 \u0432\u0440\u0435\u043c\u044f \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u0447\u0442\u0438 \u0432 \u0434\u0432\u0430 \u0440\u0430\u0437\u0430. \u0410 \u043c\u043e\u0436\u043d\u043e \u0435\u0449\u0451 \u0431\u044b\u0441\u0442\u0440\u0435\u0435? \u041c\u043e\u0436\u043d\u043e, \u0435\u0441\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0434\u0443\u043c\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b \u0441\u0431\u043e\u0440\u0430 \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u0438.<\/p>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u043e\u0434\u0443\u043b\u044f threading \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0441\u0435\u0442\u044c\u044e, \u043d\u043e \u0438 \u0432 \u043b\u044e\u0431\u044b\u0445 \u0437\u0430\u0434\u0430\u0447\u0430\u0445, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441 \u0432\u0432\u043e\u0434\u043e\u043c-\u0432\u044b\u0432\u043e\u0434\u043e\u043c.<\/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\/671198\/\"> https:\/\/habr.com\/ru\/post\/671198\/<\/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>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u043a\u0430\u043a \u043e\u0434\u0438\u043d \u0438\u0437 \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u0432, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0440\u0435\u0448\u0430\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0438, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u0432\u0432\u043e\u0434\u043e\u043c-\u0432\u044b\u0432\u043e\u0434\u043e\u043c, \u0438 \u043d\u0430 \u0435\u0433\u043e \u043e\u0441\u043d\u043e\u0432\u0435 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043f\u0430\u0440\u0441\u0435\u0440.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u0441\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0447\u0430\u0441\u0442\u043e, \u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c \u0444\u0430\u043a\u0442\u043e\u0440\u043e\u043c, \u0432\u043b\u0438\u044f\u044e\u0449\u0438\u043c \u043d\u0430 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0435\u0451 \u0440\u0435\u0448\u0435\u043d\u0438\u044f, \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u043e\u0431\u044a\u0451\u043c \u0434\u0430\u043d\u043d\u044b\u0445, \u043f\u043e\u0440\u043e\u0436\u0434\u0430\u044e\u0449\u0438\u0439 \u0431\u043e\u043b\u044c\u0448\u0435\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0439 \u043a \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0443 \u043f\u043e \u0441\u0435\u0442\u0438, \u043f\u0440\u0438\u0447\u0451\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0437\u0430\u0442\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c\u043e\u0433\u043e \u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0441\u0435\u0442\u044c\u044e, \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u0435 \u043e\u0442\u0432\u0435\u0442\u0430 \u043e\u0442 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430.<\/p>\n<p>\u0423\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u043e\u0442\u0432\u0435\u0442\u0430 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0441\u0435\u0442\u044c\u044e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f, \u043f\u043e\u0434\u0437\u0430\u0434\u0430\u0447\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u043c\u0435\u0436\u0434\u0443 \u043f\u043e\u0442\u043e\u043a\u0430\u043c\u0438.<\/p>\n<p>\u0421\u043e\u0431\u0435\u0440\u0451\u043c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0442\u0438\u0445\u043e\u0432 \u043f\u043e\u044d\u0442\u043e\u0432-\u043a\u043b\u0430\u0441\u0441\u0438\u043a\u043e\u0432 \u0438\u0437 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u0433\u043e \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430, \u043e\u0446\u0435\u043d\u0438\u043c \u0437\u0430\u0442\u0440\u0430\u0447\u0435\u043d\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0438 \u0443\u0441\u043a\u043e\u0440\u0438\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u0431\u043e\u0440\u0430. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0443\u0434\u0435\u043c Python, \u043c\u043e\u0434\u0443\u043b\u0438: bs4, json, os, queue, requests, time \u0438 threading.<\/p>\n<p>\u041f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043f\u043e \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0441\u044b\u043b\u043a\u0435 \u0438\u0437 \u043f\u043e\u0438\u0441\u043a\u043e\u0432\u0438\u043a\u0430:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u0432\u0438\u0434\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b, \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u044b\u0432\u043e\u0434 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u043f\u043e \u0430\u0432\u0442\u043e\u0440\u0430\u043c \u043d\u0435\u0442 \u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0430\u0432\u0442\u043e\u0440\u0430 \u043c\u043e\u0433\u0443\u0442 \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u0442\u044c\u0441\u044f \u043a\u0430\u043a \u043d\u0430 \u043f\u0435\u0440\u0432\u043e\u0439, \u0442\u0430\u043a \u0438 \u043d\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430\u0445, \u0443\u0447\u0442\u0451\u043c \u044d\u0442\u043e.<\/p>\n<p>\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430, \u0438\u0434\u0451\u043c \u043d\u0430 \u0432\u043a\u043b\u0430\u0434\u043a\u0443 \u00ab\u0441\u0435\u0442\u044c\u00bb, \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u043b\u044e\u0431\u043e\u0433\u043e \u0430\u0432\u0442\u043e\u0440\u0430:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041d\u0430\u0448\u043b\u0438 \u0430\u0434\u0440\u0435\u0441, \u043f\u0440\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439, \u0432\u0435\u0440\u043d\u0451\u0442\u0441\u044f json \u0441 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f\u043c\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0433\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0430\u0432\u0442\u043e\u0440\u0430.<\/p>\n<p>\u0418\u043c\u043f\u043e\u0440\u0442\u044b:<\/p>\n<pre><code>from bs4 import BeautifulSoup import json import os import requests import time<\/code><\/pre>\n<p>\u0412 \u0440\u0430\u043c\u043a\u0430\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0432\u044b\u0433\u0440\u0443\u0436\u0430\u044e\u0449\u0435\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u0430\u0432\u0442\u043e\u0440\u0443, \u043f\u0440\u043e\u0439\u0434\u0451\u043c \u043f\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c \u0441\u0441\u044b\u043b\u043a\u0430\u043c, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0431\u0440\u0430\u0442\u044c cookie, \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u0434\u043b\u044f \u043c\u043e\u0434\u0443\u043b\u044f requests \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438, \u0431\u0443\u0434\u0435\u043c \u0446\u0438\u043a\u043b\u0438\u0447\u043d\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0438 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c json-\u043e\u0442\u0432\u0435\u0442\u044b, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044f \u0438\u0445 \u0432 \u0444\u0430\u0439\u043b:<\/p>\n<pre><code>def getForAuthor(sess, author):     urls = [\"https:\/\/www.google.ru\/\", \"https:\/\/www.youtube.com\/\"]      for i in urls:         sess.get(url=i)      headers = {         \"accept\": \"*\/*\",         \"user-agent\": \"Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/99.0.4844.84 Safari\/537.36\"     }      result = {}     page = 1     while True:         url = f\"https:\/\/www.culture.ru\/_next\/data\/i_YUtTpPEY7K2ap4pw3Y4\/literature\/poems\/{author}.json?pathParams=author-sergei-esenin\"         params = {             \"pathParams\": author,             \"page\": page         }          while True:             try:                 res = sess.get(                     url=url,                     params=params,                     headers=headers                 )                 break             except Exception as ex:                 print(ex)         js = res.json()         maxPage = js[\"pageProps\"][\"pagination\"][\"total\"]         for item in js[\"pageProps\"][\"poems\"]:             result[item[\"_id\"]] = {                 \"id\": item[\"_id\"],                 \"title\": item[\"title\"],                 \"text\": item[\"text\"]             }          if page == maxPage:             break         page += 1              with open(f\".\/data\/{author}.json\", \"w\", encoding=\"utf-8\") as file:         file.write(json.dumps(result, ensure_ascii=False, indent=4))<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c:<\/p>\n<pre><code>if __name__ == \"__main__\":     start = 1     stop = 2     sess = requests.Session()     authors = []     maxPage = int(getMaxPage(sess=sess))     print(maxPage)     start = time.time(      for page in range(start, stop)):         print(page)         url = f\"https:\/\/www.culture.ru\/literature\/poems?page={page}\"          while True:             try:                 res = sess.get(url=url)                 break             except Exception as ex:                 print(ex)          soup = BeautifulSoup(res.text, \"html.parser\")          athrs = soup.find_all(attrs={\"class\": \"_6unAn\"})              for author in athrs:             author = author.get(\"href\").replace(\"\/literature\/poems\/\", \"\")             os.system(\"cls\")                          if author not in authors:                 authors.append(author)             print(len(authors))              for a in authors:         os.system(\"cls\")         print(a)         getForAuthor(sess = sess, author = a)          print(\"Done for\", time.time() - start, \"seconds\", len(authors))<\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0441\u044c:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0417\u0430\u0433\u043b\u044f\u043d\u0435\u043c \u0432 \u043e\u0434\u0438\u043d \u0438\u0437 \u0444\u0430\u0439\u043b\u043e\u0432, \u0447\u0442\u043e\u0431\u044b \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0432\u0441\u0451 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0442\u0430\u043a, \u043a\u0430\u043a \u043e\u0436\u0438\u0434\u0430\u043b\u043e\u0441\u044c:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c \u0440\u0430\u043d\u0435\u0435, \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432\u044b\u0433\u0440\u0443\u0436\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e \u0448\u0435\u0441\u0442\u043d\u0430\u0434\u0446\u0430\u0442\u0438 \u0430\u0432\u0442\u043e\u0440\u0430\u043c \u0441 \u043f\u0435\u0440\u0432\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0441\u0430\u0439\u0442\u0430, \u0438 \u044d\u0442\u043e \u0437\u0430\u043d\u044f\u043b\u043e \u043e\u043a\u043e\u043b\u043e \u0441\u0435\u043c\u0438 \u043c\u0438\u043d\u0443\u0442.<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u043e\u0447\u0435\u043c\u0443 \u0442\u0430\u043a \u0434\u043e\u043b\u0433\u043e? \u0418 \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u0440\u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0434\u043e\u043b\u044c\u0448\u0435 \u0432\u0441\u0435\u0433\u043e? \u041e\u0436\u0438\u0434\u0430\u043d\u0438\u0435.<\/p>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u043c\u043e\u0434\u0443\u043b\u0435\u043c threading: \u0441 \u0435\u0433\u043e \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043f\u043e\u0442\u043e\u043a\u0438, \u0432\u044b\u0433\u0440\u0443\u0436\u0430\u044e\u0449\u0438\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u0430\u0432\u0442\u043e\u0440\u0443 \u0432 \u043e\u0434\u043d\u043e\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435. \u041f\u0440\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430 \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f, \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0434\u0440\u0443\u0433\u043e\u0439, \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0432\u0440\u0435\u043c\u044f \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u0441\u044f. \u0414\u043b\u044f \u043e\u0431\u043c\u0435\u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0441 \u043f\u043e\u0442\u043e\u043a\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0438\u0437 \u043c\u043e\u0434\u0443\u043b\u044f queue.<\/p>\n<p>\u0427\u0430\u0441\u0442\u0438\u0447\u043d\u043e \u043f\u0435\u0440\u0435\u043f\u0438\u0448\u0435\u043c \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u0441\u043a\u0440\u0438\u043f\u0442. <\/p>\n<p>\u0418\u043c\u043f\u043e\u0440\u0442\u044b:<\/p>\n<pre><code>from bs4 import BeautifulSoup import json import os from queue import Queue import requests import time import threading<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432 \u043f\u043e\u0442\u043e\u043a\u0435:<\/p>\n<pre><code>def getForAuthor(task):     sess = requests.Session()     urls = [\"https:\/\/www.google.ru\/\", \"https:\/\/www.youtube.com\/\"]     for i in urls:         sess.get(url=i)      headers = {         \"accept\": \"*\/*\",         \"user-agent\": \"Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/99.0.4844.84 Safari\/537.36\"     }      result = {}     page = 1     if not task.empty():         author = task.get()         page = 1         while True:             url = f\"https:\/\/www.culture.ru\/_next\/data\/i_YUtTpPEY7K2ap4pw3Y4\/literature\/poems\/{author}.json?pathParams=author-sergei-esenin\"             params = {                 \"pathParams\": author,                 \"page\": page             }              while True:                 try:                     res = sess.get(                         url=url,                         params=params,                         headers=headers                     )                     break                 except Exception as ex:                     print(ex)             js = res.json()             maxPage = js[\"pageProps\"][\"pagination\"][\"total\"]             for item in js[\"pageProps\"][\"poems\"]:                 result[item[\"_id\"]] = {                     \"id\": item[\"_id\"],                     \"title\": item[\"title\"],                     \"text\": item[\"text\"]                 }              if page == maxPage:                 break             page += 1                      with open(f\".\/data\/{author}.json\", \"w\", encoding=\"utf-8\") as file:             file.write(json.dumps(result, ensure_ascii=False, indent=4))<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043c:<\/p>\n<pre><code>if __name__ == \"__main__\":     start = 1     stop = 2     sess = requests.Session()     authors = []     # \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 \u043e\u0447\u0435\u0440\u0435\u0434\u0438     task = Queue()     start = time.time()      for page in range(start, stop):         print(page)         url = f\"https:\/\/www.culture.ru\/literature\/poems?page={page}\"          while True:             try:                 res = sess.get(url=url)                 break             except Exception as ex:                 print(ex)          soup = BeautifulSoup(res.text, \"html.parser\")          athrs = soup.find_all(attrs={\"class\": \"_6unAn\"})              for author in athrs:             author = author.get(\"href\").replace(\"\/literature\/poems\/\", \"\")             os.system(\"cls\")                          if author not in authors:                 authors.append(author)     # \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043e\u0447\u0435\u0440\u0435\u0434\u0438         for a in authors:         task.put(a)     # \u0437\u0430\u043f\u0443\u0441\u043a \u043f\u043e\u0442\u043e\u043a\u043e\u0432     for _ in range(len(authors)):         threading.Thread(target=getForAuthor, args=(task,)).start()     # \u0446\u0438\u043a\u043b \u0441 \u0443\u0441\u043b\u043e\u0432\u0438\u0435\u043c \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0430 \u0434\u043b\u044f \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430     while True:         if threading.active_count() == 1:             break         print(\"Threading done for\", time.time() - start, \"seconds\", len(authors))<\/code><\/pre>\n<p>\u0412\u044b\u0432\u043e\u0434 \u043f\u043e \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u044e \u0440\u0430\u0431\u043e\u0442\u044b, \u043e\u0434\u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430, \u0442\u0435 \u0436\u0435 \u0448\u0435\u0441\u0442\u043d\u0430\u0434\u0446\u0430\u0442\u044c \u0430\u0432\u0442\u043e\u0440\u043e\u0432:<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c \u0434\u0435\u043b\u0430\u0435\u043c \u0432\u044b\u0432\u043e\u0434, \u0447\u0442\u043e \u0434\u043e\u0441\u0442\u0430\u043b\u0438 \u0442\u0435 \u0436\u0435 \u0441\u0430\u043c\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435, \u043d\u043e, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c, \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u043b\u0438 \u0432\u0440\u0435\u043c\u044f \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u0447\u0442\u0438 \u0432 \u0434\u0432\u0430 \u0440\u0430\u0437\u0430. \u0410 \u043c\u043e\u0436\u043d\u043e \u0435\u0449\u0451 \u0431\u044b\u0441\u0442\u0440\u0435\u0435? \u041c\u043e\u0436\u043d\u043e, \u0435\u0441\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0434\u0443\u043c\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b \u0441\u0431\u043e\u0440\u0430 \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u0438.<\/p>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u043e\u0434\u0443\u043b\u044f threading \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0432\u044b\u0441\u0438\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0441\u0435\u0442\u044c\u044e, \u043d\u043e \u0438 \u0432 \u043b\u044e\u0431\u044b\u0445 \u0437\u0430\u0434\u0430\u0447\u0430\u0445, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0445 \u0441 \u0432\u0432\u043e\u0434\u043e\u043c-\u0432\u044b\u0432\u043e\u0434\u043e\u043c.<\/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\/671198\/\"> https:\/\/habr.com\/ru\/post\/671198\/<\/a><br \/><\/br><\/br><\/p>\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-334439","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/334439","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=334439"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/334439\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=334439"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=334439"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=334439"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}