{"id":379351,"date":"2024-06-21T15:00:10","date_gmt":"2024-06-21T15:00:10","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=379351"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=379351","title":{"rendered":"<span>\u0421\u0438\u043b\u044c\u043d\u044b\u0439 \u0418\u0418. \u042d\u043b\u0438\u0440\u04302. \u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0434\u0438\u0430\u043b\u043e\u0433\u043e\u0432 ChatGPT<\/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<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/e5e\/4ae\/5e0\/e5e4ae5e04778ebd0e7b4183a5a432cc.jpg\" width=\"780\" height=\"440\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e5e\/4ae\/5e0\/e5e4ae5e04778ebd0e7b4183a5a432cc.jpg\" data-blurred=\"true\"\/><\/figure>\n<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442!<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0434\u0438\u0430\u043b\u043e\u0433\u0438 \u0432 ChatGPT \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u043c\u0438 \u0438\u0437 \u0447\u0430\u0442\u0430!<\/p>\n<p>\u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0443\u0436\u0435 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0434\u043e\u043b\u0433\u043e\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0435 ChatGPT \u0432 \u043d\u0435\u043c \u0434\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0438\u0430\u043b\u043e\u0433\u043e\u0432 \u0441 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u043c\u0438. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u043f\u0440\u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0432 \u0434\u0438\u0430\u043b\u043e\u0433\u0435, \u0441\u0441\u044b\u043b\u043a\u0430 \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f. \u0418\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0440\u0435\u0448\u0438\u043b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0434\u0438\u0430\u043b\u043e\u0433\u0438 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0447\u0435\u0440\u0435\u0437 \u0432\u0435\u0431-\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 ChatGPT, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f Selenium.  <\/p>\n<h4>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430<\/h4>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438. \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b <strong>requirements.txt<\/strong> \u0441 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u044b\u043c:<\/p>\n<p><code>undetected-chromedriver<br \/> selenium<br \/> requests<\/code> <\/p>\n<p> \u0417\u0430\u0442\u0435\u043c \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u044b (\u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438):<br \/><code>pip install -r requirements.txt<\/code>  <\/p>\n<p> \u0414\u0430\u043b\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b <strong>credentials.txt<\/strong>, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043b\u043e\u0433\u0438\u043d \u0438 \u043f\u0430\u0440\u043e\u043b\u044c \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0432\u0445\u043e\u0434\u0430 \u0432 ChatGPT:  <\/p>\n<p><code>myemail@example.com<br \/> mypassword<\/code><\/p>\n<h4>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u0430<\/h4>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0438\u043c\u043f\u043e\u0440\u0442\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0438 \u0447\u0442\u0435\u043d\u0438\u044f \u0443\u0447\u0435\u0442\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<pre><code class=\"python\">import os import time import requests from undetected_chromedriver import Chrome, ChromeOptions from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC  # \u0427\u0442\u0435\u043d\u0438\u0435 \u0443\u0447\u0435\u0442\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 with open('credentials.txt', 'r', encoding='utf-8') as f:     credentials = f.read().splitlines() email = credentials[0] password = credentials[1]<\/code><\/pre>\n<p> \u0414\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u0438 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430 (<span class=\"habrahidden\">\u0438 \u043e\u0431\u0445\u043e\u0434\u0430 cloudflare<\/span>) \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0431\u0438\u0431\u043b\u0443 <strong>undetected_chromedriver<\/strong>. <br \/>\u041d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c \u0435\u0433\u043e \u0438 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u0434\u043b\u044f \u0432\u0445\u043e\u0434\u0430 \u0432 ChatGPT:  <\/p>\n<pre><code class=\"python\"># \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 undetected_chromedriver options = ChromeOptions() options.add_argument('--no-sandbox') options.add_argument('--disable-dev-shm-usage')  with Chrome(options=options) as driver:     driver.get('https:\/\/chat.openai.com\/')     wait = WebDriverWait(driver, 10)     login_button = wait.until(EC.element_to_be_clickable((By.XPATH, '\/html\/body\/div[1]\/div[1]\/div[2]\/div[1]\/div\/div\/button[1]\/div\/span')))     login_button.click()      # \u0412\u0432\u043e\u0434 \u043b\u043e\u0433\u0438\u043d\u0430     email_field = wait.until(EC.presence_of_element_located((By.XPATH, '\/html\/body\/div\/div\/main\/section\/div[2]\/div[1]\/input')))     email_field.send_keys(email)     next_button = driver.find_element(By.XPATH, '\/html\/body\/div\/div\/main\/section\/div[2]\/button')     next_button.click()      # \u0412\u0432\u043e\u0434 \u043f\u0430\u0440\u043e\u043b\u044f     password_field = wait.until(EC.presence_of_element_located((By.XPATH, '\/html\/body\/div[1]\/main\/section\/div\/div\/div\/form\/div[1]\/div\/div[2]\/div\/input')))     password_field.send_keys(password)     login_button = driver.find_element(By.XPATH, '\/html\/body\/div[1]\/main\/section\/div\/div\/div\/form\/div[2]\/button')     login_button.click()      input(\"\u0412\u044b\u0431\u0435\u0440\u0438\u0442\u0435 \u043d\u0443\u0436\u043d\u044b\u0439 \u0434\u0438\u0430\u043b\u043e\u0433 \u0438 \u043d\u0430\u0436\u043c\u0438\u0442\u0435 Enter \u0434\u043b\u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u044f...\")<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0430\u043f\u043a\u0438 \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0442\u0435\u043a\u0441\u0442\u0430 \u0438 \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u044f \u0444\u0430\u0439\u043b\u043e\u0432:<\/p>\n<pre><code class=\"python\"># \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0430\u043f\u043e\u043a \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 if not os.path.exists('\u0414\u0438\u0430\u043b\u043e\u0433'):     os.makedirs('\u0414\u0438\u0430\u043b\u043e\u0433\/\u0412\u043b\u043e\u0436\u0435\u043d\u0438\u044f')  # \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0442\u0435\u043a\u0441\u0442\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f def save_text(message, filename):     with open(filename, 'w', encoding='utf-8') as f:         f.write(message)  # \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u044f \u0444\u0430\u0439\u043b\u0430 \u043f\u043e URL def download_file(url, dest_path):     response = requests.get(url)     with open(dest_path, 'wb') as f:         f.write(response.content)<\/code><\/pre>\n<p> \u0414\u0430\u043b\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 HTML-\u0444\u0430\u0439\u043b \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0438\u0430\u043b\u043e\u0433\u043e\u0432. \u0412 HTML \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u044b \u0441\u0442\u0438\u043b\u0438, \u0441\u0434\u0435\u043b\u0430\u043d\u043d\u044b\u0435 \u0432 \u0446\u0432\u0435\u0442\u0430\u0445 \u0432\u0435\u0431-\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 ChatGPT (<span class=\"habrahidden\">\u0434\u043b\u044f \u043a\u0440\u041e\u0441\u043e\u0442\u044b<\/span>):  <\/p>\n<pre><code class=\"xml\"># \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e HTML \u0444\u0430\u0439\u043b\u0430 html_content = \"\"\" &lt;!DOCTYPE html> &lt;html lang=\"ru\"> &lt;head>     &lt;meta charset=\"UTF-8\">     &lt;title>\u0414\u0438\u0430\u043b\u043e\u0433&lt;\/title>     &lt;link rel=\"stylesheet\" href=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/highlight.js\/11.3.1\/styles\/default.min.css\">     &lt;script src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/highlight.js\/11.3.1\/highlight.min.js\">&lt;\/script>     &lt;script>         hljs.highlightAll();          function copyCode(button) {             const code = button.parentElement.querySelector('code').innerText;             navigator.clipboard.writeText(code);             button.innerText = '\u0421\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u043e';             setTimeout(() => { button.innerText = '\u041a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c'; }, 2000);         }          function showModal(imageSrc) {             const modal = document.getElementById('imageModal');             const modalImg = document.getElementById('modalImg');             modal.style.display = 'block';             modalImg.src = imageSrc;         }          function closeModal() {             const modal = document.getElementById('imageModal');             modal.style.display = 'none';         }     &lt;\/script>     &lt;style>         body { font-family: Arial, sans-serif; line-height: 1.6; margin: 20px; background-color: #212121; color: #d1d5da; }         .user-message { color: #ececec !important; background-color: #2f2f2f !important; padding: 10px; border-radius: 8px; margin-bottom: 10px; }         .ai-message { color: #ececec !important; background-color: #212121; padding: 10px; border-radius: 8px; margin-bottom: 10px; }         .message-container { margin-bottom: 20px; }         .code-block { background-color: #000000 !important; border-left: 4px solid #00aaff; padding: 10px; position: relative; border-radius: 5px; }         .code-block code { display: block;  background-color: #000000 !important; color: #f8f8f2; }         .copy-button { position: absolute; top: 10px; right: 10px; padding: 5px; background-color: #444654; border-radius: 8px; border: 1px solid #ccc; cursor: pointer; }         .image-container { width: 200px; display: inline-block; margin: 10px; }         .image-container img { width: 100%; cursor: pointer; border-radius: 5px; }         .image-modal { display: none; position: fixed; z-index: 1000; padding-top: 100px; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgba(0,0,0,0.9); }         .image-modal-content { margin: auto; display: block; width: 80%; max-width: 700px; border-radius: 5px; }         .image-modal-content, .image-modal { animation-name: zoom; animation-duration: 0.6s; }         @keyframes zoom { from { transform: scale(0) } to { transform: scale(1) } }         .close { position: absolute; top: 50px; right: 35px; color: #f1f1f1; font-size: 40px; font-weight: bold; transition: 0.3s; }         .close:hover, .close:focus { color: #bbb; text-decoration: none; cursor: pointer; }     &lt;\/style> &lt;\/head> &lt;body> &lt;div id=\"imageModal\" class=\"image-modal\">     &lt;span class=\"close\" onclick=\"closeModal()\">&amp;times;&lt;\/span>     &lt;img class=\"image-modal-content\" id=\"modalImg\"> &lt;\/div> \"\"\" <\/code><\/pre>\n<p> \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0430\u0435\u043c \u043a \u0441\u0431\u043e\u0440\u0443 \u0432\u0441\u0435\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0438 \u0438\u0445 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435. \u0411\u0443\u0434\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c &#171;\u0430\u0432\u0442\u043e\u0440\u0441\u0442\u0432\u043e&#187; \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0442\u0435\u043a\u0441\u0442, \u043a\u043e\u0434 \u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e:  <\/p>\n<pre><code class=\"python\"># \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u043e\u0432 total_messages = 0 user_messages = 0 ai_messages = 0 skipped_msg = 0  # \u0421\u0431\u043e\u0440 \u0432\u0441\u0435\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 messages = driver.find_elements(By.XPATH, '\/\/div[contains(@class, \"group\") and contains(@class, \"flex\") and not(contains(@class, \"h-48\"))]') for idx, message in enumerate(messages):     if not message.text.strip():         skipped_msg += 1         continue  # \u041f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u0443\u0441\u0442\u044b\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f      total_messages += 1          role = \"\"     # \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u0430\u0432\u0442\u043e\u0440 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u0438\u043b\u0438 \u0418\u0418     try:         author_role_element = message.find_element(By.XPATH, '.\/\/div[@data-message-author-role]')         author_role = author_role_element.get_attribute('data-message-author-role')         if author_role == 'user':             user_messages += 1             role = \"\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\"             role_class = \"user-message\"         elif author_role == 'assistant':             ai_messages += 1             role = \"\u0418\u0418\"             role_class = \"ai-message\"         else:             continue  # \u041f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0435 \u0440\u043e\u043b\u0438     except:         continue  # \u041f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0431\u0435\u0437 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 data-message-author-role      # \u0417\u0430\u043c\u0435\u043d\u044f\u0435\u043c \u0440\u043e\u043b\u044c \u043d\u0430 \u0437\u043d\u0430\u0447\u043e\u043a \u0434\u043b\u044f \u0418\u0418     if role == \"\u0418\u0418\":         role_icon = \"&lt;img src='..\/GPT_icon.png' alt='ChatGPT Icon' width='20' height='20'>\"         role_html = f\"&lt;p>{role_icon}&lt;\/p>\"     else:         role_html = \"\"      html_content += f\"&lt;div class='message-container'>&lt;div class='{role_class}'>{role_html}\"      # \u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0442\u0435\u043a\u0441\u0442\u0430 \u0438 \u043a\u043e\u0434\u0430     text_elements = message.find_elements(By.XPATH, '.\/\/div[contains(@class, \"whitespace-pre-wrap\")]')     if text_elements:         text_content = text_elements[0].text         save_text(text_content, f'\u0414\u0438\u0430\u043b\u043e\u0433\/message_{idx}.txt')          code_elements = message.find_elements(By.XPATH, '.\/\/code[contains(@class, \"!whitespace-pre hljs\")]')         if code_elements:             for code_element in code_elements:                 code_content = code_element.text                 save_text(code_content, f'\u0414\u0438\u0430\u043b\u043e\u0433\/code_{idx}.txt')                 text_content = text_content.replace(code_content, f\"&lt;div class='code-block'>&lt;button class='copy-button' onclick='copyCode(this)'>\u041a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c&lt;\/button>&lt;pre>&lt;code>{code_content}&lt;\/code>&lt;\/pre>&lt;\/div>\")                  html_content += f\"&lt;p>{text_content}&lt;\/p>\"         print(f\"\u0421\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 {idx - skipped_msg} \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043e (\u0422\u0435\u043a\u0441\u0442: 1, \u041a\u043e\u0434: {len(code_elements)})\")      # \u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439     img_elements = message.find_elements(By.TAG_NAME, 'img')     if img_elements:         for img_idx, img_element in enumerate(img_elements):             img_url = img_element.get_attribute('src')             img_path = f'\u0412\u043b\u043e\u0436\u0435\u043d\u0438\u044f\/image_{idx}_{img_idx}.png'             download_file(img_url, f'\u0414\u0438\u0430\u043b\u043e\u0433\/{img_path}')             html_content += f\"&lt;div class='image-container'>&lt;img src='{img_path}' onclick='showModal(\\\"{img_path}\\\")'>&lt;\/div>\"         print(f\"\u0418\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f: {len(img_elements)}\", end=\", \")     else:         print(f\"\u0418\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f: 0\", end=\", \")      # \u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u043a\u0440\u0435\u043f\u043b\u0435\u043d\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432     file_elements = message.find_elements(By.XPATH, '.\/\/a[contains(@href, \"\/attachment\")]')     if file_elements:         for file_element in file_elements:             file_url = file_element.get_attribute('href')             file_name = file_element.text             file_path = f'\u0412\u043b\u043e\u0436\u0435\u043d\u0438\u044f\/{file_name}'             download_file(file_url, f'\u0414\u0438\u0430\u043b\u043e\u0433\/{file_path}')             html_content += f\"&lt;a href='{file_path}'>{file_name}&lt;\/a>\"         print(f\"\u0424\u0430\u0439\u043b\u044b: {len(file_elements)})\")     else:         print(f\"\u0424\u0430\u0439\u043b\u044b: 0)\")      html_content += \"&lt;\/div>&lt;\/div>\"<\/code><\/pre>\n<p> \u041d\u0435 \u0437\u0430\u0431\u0443\u0434\u0435\u043c \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0437\u0430\u043a\u0440\u044b\u0442\u044c HTML-\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443, \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 HTML-\u0444\u0430\u0439\u043b \u0438 \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443:  <\/p>\n<pre><code class=\"python\"># \u0417\u0430\u043a\u0440\u044b\u0442\u0438\u0435 HTML \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b html_content += \"\"\" &lt;\/body> &lt;\/html> \"\"\"  # \u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e HTML \u0444\u0430\u0439\u043b\u0430 with open('\u0414\u0438\u0430\u043b\u043e\u0433\/\u0434\u0438\u0430\u043b\u043e\u0433.html', 'w', encoding='utf-8') as f:     f.write(html_content)  # \u0412\u044b\u0432\u043e\u0434 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 print(f\"\u0412\u0441\u0435\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439: {total_messages}\") print(f\"\u0421\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f: {user_messages}\") print(f\"\u0421\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0418\u0418: {ai_messages}\")  print(\"\u0414\u0438\u0430\u043b\u043e\u0433 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d.\")<\/code><\/pre>\n<h4>\u0421\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u0440\u0435\u043f\u043e \u0441 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c:<\/h4>\n<p><a href=\"https:\/\/github.com\/Devastor\/DevastorSaveDialogues_ChatGPT\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/Devastor\/DevastorSaveDialogues_ChatGPT<\/a><\/p>\n<p>\u0442\u0430\u043c \u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u0444\u0430\u0439\u043b \u0438\u043a\u043e\u043d\u043a\u0438 (\u0434\u043b\u044f \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0418\u0418 \u0432 \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u043c \u0434\u0438\u0430\u043b\u043e\u0433\u0435)<\/p>\n<hr\/>\n<h4>\u0427\u0442\u043e \u043c\u043e\u0436\u043d\u043e (\u0438 \u043d\u0443\u0436\u043d\u043e) \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c<\/h4>\n<ol>\n<li>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439, \u043d\u043e \u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u0444\u043e\u0440\u043c\u0430\u0442\u043e\u0432 \u0432\u043b\u043e\u0436\u0435\u043d\u0438\u0439, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u0430\u0431\u043b\u0438\u0446\u044b xls, csv (\u0434\u0440\u0443\u0433\u0438\u0435 \u0432\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0436\u0438\u0432\u0443\u0442 \u0432 \u0447\u0430\u0442\u0435 \u043d\u0435\u0434\u043e\u043b\u0433\u043e, \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0442\u0430\u0431\u043b\u0438\u0446).<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0444\u0438\u043a\u0441\u0438\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443 &#171;OSError: [WinError 6] \u041d\u0435\u0432\u0435\u0440\u043d\u044b\u0439 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440&#187;, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u043b\u0435\u0442\u0430\u0435\u0442 \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0438\u0430\u043b\u043e\u0433\u0430 (\u0443 \u043c\u0435\u043d\u044f \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c, \u0445\u043e\u0442\u044f \u044f \u043d\u0435 \u043e\u0441\u043e\u0431\u043e \u0441\u0442\u0430\u0440\u0430\u043b\u0441\u044f, \u0438\u0431\u043e \u043b\u0435\u043d\u044c, \u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u043d\u0435 \u043c\u0435\u0448\u0430\u0435\u0442, \u044d\u0442\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e).<\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0432\u0441\u0435\u0445 \u0434\u0438\u0430\u043b\u043e\u0433\u043e\u0432 \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0430 \u0432 \u0446\u0438\u043a\u043b\u0435 (\u043b\u0435\u0433\u043a\u043e).<\/p>\n<\/li>\n<li>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0434\u0438\u0430\u043b\u043e\u0433\u0430 (\u043d\u0435 \u0442\u0430\u043a \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e, \u043a\u0430\u043a \u043a\u0430\u0436\u0435\u0442\u0441\u044f &#8212; \u043d\u0443\u0436\u043d\u043e \u043a\u0430\u043a-\u0442\u043e \u043f\u0440\u0438\u0434\u0443\u043c\u0430\u0442\u044c, \u043a\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043b\u043e\u0432\u0438\u0442\u044c \u0438\u043c\u044f \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 \u0442\u043e\u0433\u043e \u0434\u0438\u0430\u043b\u043e\u0433\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u044b\u0431\u0440\u0430\u043d).<\/p>\n<\/li>\n<li>\n<p>\u0423\u0431\u0440\u0430\u0442\u044c \u043b\u0438\u0448\u043d\u044e\u044e \u043a\u043d\u043e\u043f\u043a\u0443 &#171;\u041a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c&#187; \u0438\u0437 \u043f\u0440\u0430\u0432\u043e\u0433\u043e \u0432\u0435\u0440\u0445\u043d\u0435\u0433\u043e \u0443\u0433\u043b\u0430 \ud83d\ude42<\/p>\n<\/li>\n<li>\n<p>\u0421\u0434\u0435\u043b\u0430\u0442\u044c \u043b\u043e\u0433\u0438 \u043e\u0442\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u044b\u043c\u0438 (\u043b\u0443\u0447\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0432 args)<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><\/p>\n<div class=\"tm-article-poll-container\"><!--[--><\/p>\n<div class=\"tm-article-poll tm-article-poll_variant-bordered\">\n<div class=\"tm-notice tm-notice_positive tm-article-poll__notice\"><!----><\/p>\n<div class=\"tm-notice__inner\"><!----><\/p>\n<div class=\"tm-notice__content\" data-test-id=\"notice-content\"><!--[--><span>\u0422\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u043c\u043e\u0433\u0443\u0442 \u0443\u0447\u0430\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0432 \u043e\u043f\u0440\u043e\u0441\u0435. <a rel=\"nofollow\" href=\"\/kek\/v1\/auth\/habrahabr\/?back=\/ru\/articles\/823428\/&#038;hl=ru\">\u0412\u043e\u0439\u0434\u0438\u0442\u0435<\/a>, \u043f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430.<\/span><!--]--><\/div>\n<\/div>\n<\/div>\n<p><!--[--><\/p>\n<div class=\"tm-article-poll__header\">\u041f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f \u0441\u043a\u0440\u0438\u043f\u0442?<\/div>\n<div class=\"tm-article-poll__answers\"><!--[--><\/p>\n<div class=\"tm-article-poll__answer\">\n<div class=\"tm-article-poll__answer-data\"><span class=\"tm-article-poll__answer-percent tm-article-poll__answer-percent_winning\">57.14% <\/span><span class=\"tm-article-poll__answer-label\">\u0414\u0430, \u043f\u043e\u043b\u0435\u0437\u043d\u0430\u044f \u0448\u0442\u0443\u043a\u0430!<\/span><span class=\"tm-article-poll__answer-votes\">4<\/span><\/div>\n<div class=\"tm-article-poll__answer-bar\">\n<div class=\"tm-article-poll__answer-progress tm-article-poll__answer-progress_winning\" style=\"width: 57.14%\"><\/div>\n<\/div>\n<\/div>\n<div class=\"tm-article-poll__answer\">\n<div class=\"tm-article-poll__answer-data\"><span class=\"tm-article-poll__answer-percent\">28.57% <\/span><span class=\"tm-article-poll__answer-label\">\u041d\u0435\u0442, \u0437\u0430\u0447\u0435\u043c \u043e\u043d\u043e \u0432\u043e\u043e\u0431\u0449\u0435?<\/span><span class=\"tm-article-poll__answer-votes\">2<\/span><\/div>\n<div class=\"tm-article-poll__answer-bar\">\n<div class=\"tm-article-poll__answer-progress\" style=\"width: 28.57%\"><\/div>\n<\/div>\n<\/div>\n<div class=\"tm-article-poll__answer\">\n<div class=\"tm-article-poll__answer-data\"><span class=\"tm-article-poll__answer-percent\">14.29% <\/span><span class=\"tm-article-poll__answer-label\">\u041b\u0443\u0447\u0448\u0435 \u043d\u0430\u043f\u0438\u0448\u0443 \u0441\u0432\u043e\u0439)<\/span><span class=\"tm-article-poll__answer-votes\">1<\/span><\/div>\n<div class=\"tm-article-poll__answer-bar\">\n<div class=\"tm-article-poll__answer-progress\" style=\"width: 14.29%\"><\/div>\n<\/div>\n<\/div>\n<p><!--]--><\/div>\n<div class=\"tm-article-poll__stats\"> \u041f\u0440\u043e\u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0430\u043b\u0438 7 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439.   \u0412\u043e\u0437\u0434\u0435\u0440\u0436\u0430\u043b\u0438\u0441\u044c 2 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. <\/div>\n<p><!--]--><\/div>\n<p><!--]--><\/div>\n<p> \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\/articles\/823428\/\"> https:\/\/habr.com\/ru\/articles\/823428\/<\/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<figure class=\"full-width\"><\/figure>\n<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442!<\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0434\u0438\u0430\u043b\u043e\u0433\u0438 \u0432 ChatGPT \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u043c\u0438 \u0438\u0437 \u0447\u0430\u0442\u0430!<\/p>\n<p>\u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0443\u0436\u0435 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0434\u043e\u043b\u0433\u043e\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0435 ChatGPT \u0432 \u043d\u0435\u043c \u0434\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0438\u0430\u043b\u043e\u0433\u043e\u0432 \u0441 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u043c\u0438. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u043f\u0440\u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0432 \u0434\u0438\u0430\u043b\u043e\u0433\u0435, \u0441\u0441\u044b\u043b\u043a\u0430 \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f. \u0418\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0440\u0435\u0448\u0438\u043b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0434\u0438\u0430\u043b\u043e\u0433\u0438 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0447\u0435\u0440\u0435\u0437 \u0432\u0435\u0431-\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 ChatGPT, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f Selenium.  <\/p>\n<h4>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430<\/h4>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438. \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b <strong>requirements.txt<\/strong> \u0441 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u044b\u043c:<\/p>\n<p><code>undetected-chromedriver<br \/> selenium<br \/> requests<\/code> <\/p>\n<p> \u0417\u0430\u0442\u0435\u043c \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u044b (\u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u0438):<br \/><code>pip install -r requirements.txt<\/code>  <\/p>\n<p> \u0414\u0430\u043b\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b <strong>credentials.txt<\/strong>, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043b\u043e\u0433\u0438\u043d \u0438 \u043f\u0430\u0440\u043e\u043b\u044c \u0434\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0432\u0445\u043e\u0434\u0430 \u0432 ChatGPT:  <\/p>\n<p><code>myemail@example.com<br \/> mypassword<\/code><\/p>\n<h4>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u0430<\/h4>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0438\u043c\u043f\u043e\u0440\u0442\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0438 \u0447\u0442\u0435\u043d\u0438\u044f \u0443\u0447\u0435\u0442\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<pre><code class=\"python\">import os import time import requests from undetected_chromedriver import Chrome, ChromeOptions from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC  # \u0427\u0442\u0435\u043d\u0438\u0435 \u0443\u0447\u0435\u0442\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 with open('credentials.txt', 'r', encoding='utf-8') as f:     credentials = f.read().splitlines() email = credentials[0] password = credentials[1]<\/code><\/pre>\n<p> \u0414\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u0438 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u0430 (<span class=\"habrahidden\">\u0438 \u043e\u0431\u0445\u043e\u0434\u0430 cloudflare<\/span>) \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0431\u0438\u0431\u043b\u0443 <strong>undetected_chromedriver<\/strong>. <br \/>\u041d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c \u0435\u0433\u043e \u0438 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0443 \u0434\u043b\u044f \u0432\u0445\u043e\u0434\u0430 \u0432 ChatGPT:  <\/p>\n<pre><code class=\"python\"># \u041d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 undetected_chromedriver options = ChromeOptions() options.add_argument('--no-sandbox') options.add_argument('--disable-dev-shm-usage')  with Chrome(options=options) as driver:     driver.get('https:\/\/chat.openai.com\/')     wait = WebDriverWait(driver, 10)     login_button = wait.until(EC.element_to_be_clickable((By.XPATH, '\/html\/body\/div[1]\/div[1]\/div[2]\/div[1]\/div\/div\/button[1]\/div\/span')))     login_button.click()      # \u0412\u0432\u043e\u0434 \u043b\u043e\u0433\u0438\u043d\u0430     email_field = wait.until(EC.presence_of_element_located((By.XPATH, '\/html\/body\/div\/div\/main\/section\/div[2]\/div[1]\/input')))     email_field.send_keys(email)     next_button = driver.find_element(By.XPATH, '\/html\/body\/div\/div\/main\/section\/div[2]\/button')     next_button.click()      # \u0412\u0432\u043e\u0434 \u043f\u0430\u0440\u043e\u043b\u044f     password_field = wait.until(EC.presence_of_element_located((By.XPATH, '\/html\/body\/div[1]\/main\/section\/div\/div\/div\/form\/div[1]\/div\/div[2]\/div\/input')))     password_field.send_keys(password)     login_button = driver.find_element(By.XPATH, '\/html\/body\/div[1]\/main\/section\/div\/div\/div\/form\/div[2]\/button')     login_button.click()      input(\"\u0412\u044b\u0431\u0435\u0440\u0438\u0442\u0435 \u043d\u0443\u0436\u043d\u044b\u0439 \u0434\u0438\u0430\u043b\u043e\u0433 \u0438 \u043d\u0430\u0436\u043c\u0438\u0442\u0435 Enter \u0434\u043b\u044f \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u044f...\")<\/code><\/pre>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u0430\u043f\u043a\u0438 \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0442\u0435\u043a\u0441\u0442\u0430 \u0438 \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u044f \u0444\u0430\u0439\u043b\u043e\u0432:<\/p>\n<pre><code class=\"python\"># \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u0430\u043f\u043e\u043a \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 if not os.path.exists('\u0414\u0438\u0430\u043b\u043e\u0433'):     os.makedirs('\u0414\u0438\u0430\u043b\u043e\u0433\/\u0412\u043b\u043e\u0436\u0435\u043d\u0438\u044f')  # \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0442\u0435\u043a\u0441\u0442\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f def save_text(message, filename):     with open(filename, 'w', encoding='utf-8') as f:         f.write(message)  # \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043b\u044f \u0441\u043a\u0430\u0447\u0438\u0432\u0430\u043d\u0438\u044f \u0444\u0430\u0439\u043b\u0430 \u043f\u043e URL def download_file(url, dest_path):     response = requests.get(url)     with open(dest_path, 'wb') as f:         f.write(response.content)<\/code><\/pre>\n<p> \u0414\u0430\u043b\u0435\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 HTML-\u0444\u0430\u0439\u043b \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0438\u0430\u043b\u043e\u0433\u043e\u0432. \u0412 HTML \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u044b \u0441\u0442\u0438\u043b\u0438, \u0441\u0434\u0435\u043b\u0430\u043d\u043d\u044b\u0435 \u0432 \u0446\u0432\u0435\u0442\u0430\u0445 \u0432\u0435\u0431-\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 ChatGPT (<span class=\"habrahidden\">\u0434\u043b\u044f \u043a\u0440\u041e\u0441\u043e\u0442\u044b<\/span>):  <\/p>\n<pre><code class=\"xml\"># \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e HTML \u0444\u0430\u0439\u043b\u0430 html_content = \"\"\" &lt;!DOCTYPE html> &lt;html lang=\"ru\"> &lt;head>     &lt;meta charset=\"UTF-8\">     &lt;title>\u0414\u0438\u0430\u043b\u043e\u0433&lt;\/title>     &lt;link rel=\"stylesheet\" href=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/highlight.js\/11.3.1\/styles\/default.min.css\">     &lt;script src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/highlight.js\/11.3.1\/highlight.min.js\">&lt;\/script>     &lt;script>         hljs.highlightAll();          function copyCode(button) {             const code = button.parentElement.querySelector('code').innerText;             navigator.clipboard.writeText(code);             button.innerText = '\u0421\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u043e';             setTimeout(() => { button.innerText = '\u041a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c'; }, 2000);         }          function showModal(imageSrc) {             const modal = document.getElementById('imageModal');             const modalImg = document.getElementById('modalImg');             modal.style.display = 'block';             modalImg.src = imageSrc;         }          function closeModal() {             const modal = document.getElementById('imageModal');             modal.style.display = 'none';         }     &lt;\/script>     &lt;style>         body { font-family: Arial, sans-serif; line-height: 1.6; margin: 20px; background-color: #212121; color: #d1d5da; }         .user-message { color: #ececec !important; background-color: #2f2f2f !important; padding: 10px; border-radius: 8px; margin-bottom: 10px; }         .ai-message { color: #ececec !important; background-color: #212121; padding: 10px; border-radius: 8px; margin-bottom: 10px; }         .message-container { margin-bottom: 20px; }         .code-block { background-color: #000000 !important; border-left: 4px solid #00aaff; padding: 10px; position: relative; border-radius: 5px; }         .code-block code { display: block;  background-color: #000000 !important; color: #f8f8f2; }         .copy-button { position: absolute; top: 10px; right: 10px; padding: 5px; background-color: #444654; border-radius: 8px; border: 1px solid #ccc; cursor: pointer; }         .image-container { width: 200px; display: inline-block; margin: 10px; }         .image-container img { width: 100%; cursor: pointer; border-radius: 5px; }         .image-modal { display: none; position: fixed; z-index: 1000; padding-top: 100px; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgba(0,0,0,0.9); }         .image-modal-content { margin: auto; display: block; width: 80%; max-width: 700px; border-radius: 5px; }         .image-modal-content, .image-modal { animation-name: zoom; animation-duration: 0.6s; }         @keyframes zoom { from { transform: scale(0) } to { transform: scale(1) } }         .close { position: absolute; top: 50px; right: 35px; color: #f1f1f1; font-size: 40px; font-weight: bold; transition: 0.3s; }         .close:hover, .close:focus { color: #bbb; text-decoration: none; cursor: pointer; }     &lt;\/style> &lt;\/head> &lt;body> &lt;div id=\"imageModal\" class=\"image-modal\">     &lt;span class=\"close\" onclick=\"closeModal()\">&amp;times;&lt;\/span>     &lt;img class=\"image-modal-content\" id=\"modalImg\"> &lt;\/div> \"\"\" <\/code><\/pre>\n<p> \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0430\u0435\u043c \u043a \u0441\u0431\u043e\u0440\u0443 \u0432\u0441\u0435\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0438 \u0438\u0445 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435. \u0411\u0443\u0434\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c &#171;\u0430\u0432\u0442\u043e\u0440\u0441\u0442\u0432\u043e&#187; \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0442\u0435\u043a\u0441\u0442, \u043a\u043e\u0434 \u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e:  <\/p>\n<pre><code class=\"python\"># \u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u043e\u0432 total_messages = 0 user_messages = 0 ai_messages = 0 skipped_msg = 0  # \u0421\u0431\u043e\u0440 \u0432\u0441\u0435\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 messages = driver.find_elements(By.XPATH, '\/\/div[contains(@class, \"group\") and contains(@class, \"flex\") and not(contains(@class, \"h-48\"))]') for idx, message in enumerate(messages):     if not message.text.strip():         skipped_msg += 1         continue  # \u041f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u0443\u0441\u0442\u044b\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f      total_messages += 1          role = \"\"     # \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u0430\u0432\u0442\u043e\u0440 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u0438\u043b\u0438 \u0418\u0418     try:         author_role_element = message.find_element(By.XPATH, '.\/\/div[@data-message-author-role]')         author_role = author_role_element.get_attribute('data-message-author-role')         if author_role == 'user':             user_messages += 1             role = \"\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\"             role_class = \"user-message\"         elif author_role == 'assistant':             ai_messages += 1             role = \"\u0418\u0418\"             role_class = \"ai-message\"         else:             continue  # \u041f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b\u0435 \u0440\u043e\u043b\u0438     except:         continue  # \u041f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0431\u0435\u0437 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 data-message-author-role      # \u0417\u0430\u043c\u0435\u043d\u044f\u0435\u043c \u0440\u043e\u043b\u044c \u043d\u0430 \u0437\u043d\u0430\u0447\u043e\u043a \u0434\u043b\u044f \u0418\u0418     if role == \"\u0418\u0418\":         role_icon = \"&lt;img src='..\/GPT_icon.png' alt='ChatGPT Icon' width='20' height='20'>\"         role_html = f\"&lt;p>{role_icon}&lt;\/p>\"     else:         role_html = \"\"      html_content += f\"&lt;div class='message-container'>&lt;div class='{role_class}'>{role_html}\"      # \u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0442\u0435\u043a\u0441\u0442\u0430 \u0438 \u043a\u043e\u0434\u0430     text_elements = message.find_elements(By.XPATH, '.\/\/div[contains(@class, \"whitespace-pre-wrap\")]')     if text_elements:         text_content = text_elements[0].text         save_text(text_content, f'\u0414\u0438\u0430\u043b\u043e\u0433\/message_{idx}.txt')          code_elements = message.find_elements(By.XPATH, '.\/\/code[contains(@class, \"!whitespace-pre hljs\")]')         if code_elements:             for code_element in code_elements:                 code_content = code_element.text                 save_text(code_content, f'\u0414\u0438\u0430\u043b\u043e\u0433\/code_{idx}.txt')                 text_content = text_content.replace(code_content, f\"&lt;div class='code-block'>&lt;button class='copy-button' onclick='copyCode(this)'>\u041a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c&lt;\/button>&lt;pre>&lt;code>{code_content}&lt;\/code>&lt;\/pre>&lt;\/div>\")                  html_content += f\"&lt;p>{text_content}&lt;\/p>\"         print(f\"\u0421\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 {idx - skipped_msg} \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u043e (\u0422\u0435\u043a\u0441\u0442: 1, \u041a\u043e\u0434: {len(code_elements)})\")      # \u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439     img_elements = message.find_elements(By.TAG_NAME, 'img')     if img_elements:         for img_idx, img_element in enumerate(img_elements):             img_url = img_element.get_attribute('src')             img_path = f'\u0412\u043b\u043e\u0436\u0435\u043d\u0438\u044f\/image_{idx}_{img_idx}.png'             download_file(img_url, f'\u0414\u0438\u0430\u043b\u043e\u0433\/{img_path}')             html_content += f\"&lt;div class='image-container'>&lt;img src='{img_path}' onclick='showModal(\\\"{img_path}\\\")'>&lt;\/div>\"         print(f\"\u0418\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f: {len(img_elements)}\", end=\", \")     else:         print(f\"\u0418\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f: 0\", end=\", \")      # \u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u043a\u0440\u0435\u043f\u043b\u0435\u043d\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432     file_elements = message.find_elements(By.XPATH, '.\/\/a[contains(@href, \"\/attachment\")]')     if file_elements:         for file_element in file_elements:             file_url = file_element.get_attribute('href')             file_name = file_element.text             file_path = f'\u0412\u043b\u043e\u0436\u0435\u043d\u0438\u044f\/{file_name}'             download_file(file_url, f'\u0414\u0438\u0430\u043b\u043e\u0433\/{file_path}')             html_content += f\"&lt;a<\/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-379351","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/379351","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=379351"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/379351\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=379351"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=379351"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=379351"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}