from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.select import Select
import os
import os.path
import sys
from time import sleep
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import pickle
import datetime
dt_now = datetime.datetime.now()
PATH = os.path.split(os.path.abspath(os.path.realpath(sys.argv[0])))[0] + '/'
options = Options()
options.add_argument("--mute-audio")
options.add_argument("--disable-blink-features=AutomationControlled")
options.headless = False
options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36")
driver = webdriver.Chrome(executable_path=PATH + "chromedriver",
options=options)
with open('settings.txt' , 'r') as file:
text = file.readlines()
for line in text:
if 'Запрос на поиск' in line:
constipation = str(line.replace('Запрос на поиск - ', ''))
constipation = constipation.strip()
elif 'Количевство взятых из поиска видео' in line:
vd = int(line.replace('Количевство взятых из поиска видео - ', ''))
elif 'Текст комментария' in line:
comments_text = str(line.replace('Текст комментария - ', ''))
comments_text = comments_text.strip()
elif 'Количевство отправленных комментариев' in line:
vdcomments = int(line.replace('Количевство отправленных комментариев - ', ''))
try:
print('Захожу на сайт')
with open('logs.txt' , 'a') as file:
file.write('[ ' + str(dt_now) + ' ]' + ' Бот заходит на ютуб' + '\n')
driver.set_window_position(9999999, 99999999)
driver.get('https://www.youtube.com/')
for cookie in pickle.load(open('cookies_to_youtube', 'rb')):
driver.add_cookie(cookie)
sleep(2)
driver.refresh()
#pickle.dump(driver.get_cookies(), open('cookies_to_youtube', 'wb'))
#driver.get('https://www.youtube.com/')
driver.implicitly_wait(5)
with open('logs.txt' , 'a') as file:
file.write('[ ' + str(dt_now) + ' ]' + ' Бот ищет видео по запросу ' + constipation + '\n')
search = driver.find_element_by_name('search_query')
search.clear()
search.send_keys(constipation)
sleep(1)
search.send_keys(Keys.ENTER)
sleep(3)
driver.implicitly_wait(5)
videos = driver.find_elements_by_class_name('text-wrapper')
for video in range(0, vd):
videos[video].click()
driver.implicitly_wait(5)
with open('logs.txt' , 'a') as file:
file.write('[ ' + str(dt_now) + ' ]' + ' Бот зашёл на видео: ' + driver.current_url + '\n')
sleep(5)
qcom = 0
#Send the keys to the input field
for comment in range(0, vdcomments):
driver.implicitly_wait(2)
if 20 < qcom:
qcom = 0
commentBox = driver.find_element_by_id('placeholder-area')
commentBox.click()
sleep(1)
inputBox =driver.find_element_by_id('contenteditable-root')
inputBox.send_keys('$')
sleep(0.5)
inputBox.send_keys(Keys.CONTROL + Keys.ENTER)
else:
commentBox = driver.find_element_by_id('placeholder-area')
commentBox.click()
sleep(1)
inputBox =driver.find_element_by_id('contenteditable-root')
inputBox.send_keys(comments_text)
sleep(0.5)
#driver.find_element_by_partial_link_text('КОММЕНТАРИЙ').click()
inputBox.send_keys(Keys.CONTROL + Keys.ENTER)
sleep(1.5)
qcom = qcom + 1
with open('logs.txt' , 'a') as file:
file.write('[ ' + str(dt_now) + ' ]' + ' Бот оставил комментарии' + '\n')
sleep(1)
driver.back()
sleep(1)
sleep(3)
print('Операция завершина успешно!')
except Exception as ex:
print(ex)
finally:
driver.close()
driver.quit()
message.from_user.first_name
даёт имя бота from fake_useragent import UserAgent
ua = UserAgent()
options.add_argument(f'user-agent={ua.google}')
driver = webdriver.Chrome(executable_path=PATH + "chromedriver",
options=options)
Microsoft Windows [Version 10.0.17763.2114]
(c) Корпорация Майкрософт (Microsoft Corporation), 2018. Все права защищены.
C:\Users\Дом>pip install face-recognition
Collecting face-recognition
Cache entry deserialization failed, entry ignored
Cache entry deserialization failed, entry ignored
Downloading https://files.pythonhosted.org/packages/1e/95/f6c9330f54ab07bfa032bf3715c12455a381083125d8880c43cbe76bb3d0/face_recognition-1.3.0-py2.py3-none-any.whl
Collecting Pillow (from face-recognition)
Cache entry deserialization failed, entry ignored
Downloading https://files.pythonhosted.org/packages/ea/93/23b8524c64790729ba443b49462012a817c0152f2b78105331140f9da1b9/Pillow-8.3.2-cp36-cp36m-win_amd64.whl (3.2MB)
100% |████████████████████████████████| 3.2MB 361kB/s
Collecting dlib>=19.7 (from face-recognition)
Cache entry deserialization failed, entry ignored
Cache entry deserialization failed, entry ignored
Downloading https://files.pythonhosted.org/packages/f0/a2/ba6163c09fb427990180afd8d625bcecc5555af699c253193c35ffd48c4f/dlib-19.22.1.tar.gz (7.4MB)
100% |████████████████████████████████| 7.4MB 156kB/s
Collecting face-recognition-models>=0.3.0 (from face-recognition)
Cache entry deserialization failed, entry ignored
Cache entry deserialization failed, entry ignored
Downloading https://files.pythonhosted.org/packages/cf/3b/4fd8c534f6c0d1b80ce0973d01331525538045084c73c153ee6df20224cf/face_recognition_models-0.3.0.tar.gz (100.1MB)
100% |████████████████████████████████| 100.2MB 10.0kB/s
Collecting Click>=6.0 (from face-recognition)
Cache entry deserialization failed, entry ignored
Cache entry deserialization failed, entry ignored
Downloading https://files.pythonhosted.org/packages/76/0a/b6c5f311e32aeb3b406e03c079ade51e905ea630fc19d1262a46249c1c86/click-8.0.1-py3-none-any.whl (97kB)
100% |████████████████████████████████| 102kB 4.7MB/s
Collecting numpy (from face-recognition)
Cache entry deserialization failed, entry ignored
Downloading https://files.pythonhosted.org/packages/ea/bc/da526221bc111857c7ef39c3af670bbcf5e69c247b0d22e51986f6d0c5c2/numpy-1.19.5-cp36-cp36m-win_amd64.whl (13.2MB)
100% |████████████████████████████████| 13.2MB 88kB/s
Collecting importlib-metadata; python_version < "3.8" (from Click>=6.0->face-recognition)
Cache entry deserialization failed, entry ignored
Cache entry deserialization failed, entry ignored
Downloading https://files.pythonhosted.org/packages/71/c2/cb1855f0b2a0ae9ccc9b69f150a7aebd4a8d815bd951e74621c4154c52a8/importlib_metadata-4.8.1-py3-none-any.whl
Collecting colorama; platform_system == "Windows" (from Click>=6.0->face-recognition)
Cache entry deserialization failed, entry ignored
Cache entry deserialization failed, entry ignored
Downloading https://files.pythonhosted.org/packages/44/98/5b86278fbbf250d239ae0ecb724f8572af1c91f4a11edf4d36a206189440/colorama-0.4.4-py2.py3-none-any.whl
Collecting zipp>=0.5 (from importlib-metadata; python_version < "3.8"->Click>=6.0->face-recognition)
Cache entry deserialization failed, entry ignored
Cache entry deserialization failed, entry ignored
Downloading https://files.pythonhosted.org/packages/92/d9/89f433969fb8dc5b9cbdd4b4deb587720ec1aeb59a020cf15002b9593eef/zipp-3.5.0-py3-none-any.whl
Collecting typing-extensions>=3.6.4; python_version < "3.8" (from importlib-metadata; python_version < "3.8"->Click>=6.0->face-recognition)
Cache entry deserialization failed, entry ignored
Cache entry deserialization failed, entry ignored
Downloading https://files.pythonhosted.org/packages/74/60/18783336cc7fcdd95dae91d73477830aa53f5d3181ae4fe20491d7fc3199/typing_extensions-3.10.0.2-py3-none-any.whl
Installing collected packages: Pillow, dlib, face-recognition-models, zipp, typing-extensions, importlib-metadata, colorama, Click, numpy, face-recognition
Running setup.py install for dlib ... error
Exception:
Traceback (most recent call last):
File "c:\users\дом\appdata\local\programs\python\python36\lib\site-packages\pip\compat\__init__.py", line 73, in console_to_str
return s.decode(sys.__stdout__.encoding)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe4 in position 246: invalid continuation byte
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\users\дом\appdata\local\programs\python\python36\lib\site-packages\pip\commands\install.py", line 342, in run
prefix=options.prefix_path,
File "c:\users\дом\appdata\local\programs\python\python36\lib\site-packages\pip\req\req_set.py", line 784, in install
**kwargs
File "c:\users\дом\appdata\local\programs\python\python36\lib\site-packages\pip\req\req_install.py", line 878, in install
spinner=spinner,
File "c:\users\дом\appdata\local\programs\python\python36\lib\site-packages\pip\utils\__init__.py", line 676, in call_subprocess
line = console_to_str(proc.stdout.readline())
File "c:\users\дом\appdata\local\programs\python\python36\lib\site-packages\pip\compat\__init__.py", line 75, in console_to_str
return s.decode('utf_8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe4 in position 246: invalid continuation byte
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\users\дом\appdata\local\programs\python\python36\lib\site-packages\pip\basecommand.py", line 215, in main
status = self.run(options, args)
File "c:\users\дом\appdata\local\programs\python\python36\lib\site-packages\pip\commands\install.py", line 385, in run
requirement_set.cleanup_files()
File "c:\users\дом\appdata\local\programs\python\python36\lib\site-packages\pip\req\req_set.py", line 729, in cleanup_files
req.remove_temporary_source()
File "c:\users\дом\appdata\local\programs\python\python36\lib\site-packages\pip\req\req_install.py", line 977, in remove_temporary_source
rmtree(self.source_dir)
File "c:\users\дом\appdata\local\programs\python\python36\lib\site-packages\pip\_vendor\retrying.py", line 49, in wrapped_f
return Retrying(*dargs, **dkw).call(f, *args, **kw)
File "c:\users\дом\appdata\local\programs\python\python36\lib\site-packages\pip\_vendor\retrying.py", line 212, in call
raise attempt.get()
File "c:\users\дом\appdata\local\programs\python\python36\lib\site-packages\pip\_vendor\retrying.py", line 247, in get
six.reraise(self.value[0], self.value[1], self.value[2])
File "c:\users\дом\appdata\local\programs\python\python36\lib\site-packages\pip\_vendor\six.py", line 686, in reraise
raise value
File "c:\users\дом\appdata\local\programs\python\python36\lib\site-packages\pip\_vendor\retrying.py", line 200, in call
attempt = Attempt(fn(*args, **kwargs), attempt_number, False)
File "c:\users\дом\appdata\local\programs\python\python36\lib\site-packages\pip\utils\__init__.py", line 102, in rmtree
onerror=rmtree_errorhandler)
File "c:\users\дом\appdata\local\programs\python\python36\lib\shutil.py", line 488, in rmtree
return _rmtree_unsafe(path, onerror)
File "c:\users\дом\appdata\local\programs\python\python36\lib\shutil.py", line 378, in _rmtree_unsafe
_rmtree_unsafe(fullname, onerror)
File "c:\users\дом\appdata\local\programs\python\python36\lib\shutil.py", line 378, in _rmtree_unsafe
_rmtree_unsafe(fullname, onerror)
File "c:\users\дом\appdata\local\programs\python\python36\lib\shutil.py", line 378, in _rmtree_unsafe
_rmtree_unsafe(fullname, onerror)
[Previous line repeated 2 more times]
File "c:\users\дом\appdata\local\programs\python\python36\lib\shutil.py", line 387, in _rmtree_unsafe
onerror(os.rmdir, path, sys.exc_info())
File "c:\users\дом\appdata\local\programs\python\python36\lib\site-packages\pip\utils\__init__.py", line 114, in rmtree_errorhandler
func(path)
PermissionError: [WinError 32] Процесс не может получить доступ к файлу, так как этот файл занят другим процессом: 'C:\\Users\\E786~1\\AppData\\Local\\Temp\\pip-build-ey04e_8p\\dlib\\build\\temp.win-amd64-3.6\\Release\\CMakeFiles\\3.21.1\\CompilerIdC'
You are using pip version 9.0.1, however version 21.2.4 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.