from selenium import webdriver
from time import sleep
from PIL import Image
from pytesseract import image_to_string
class Bot_dzen:
def __init__(self):
self.driver = webdriver.Firefox(executable_path='C:\\Users\\ilya_pc\\Documents\\gecko\\geckodriver.exe')
self.navigate()
def views_recon(self):
image = Image.open('views.gif')
image_link = image_to_string(image).split('@ ')
views_dzen = int(image_link[0])
views_dzen_2 = int(image_link[1])
views_dzen_3 = int(image_link[2])
def crop(self, location, size):
image = Image.open('dzen_pars.png')
x =location['x']
y = location['y']
width = size['width']
height = size['height']
image.crop((x, y, x+width, y+height)).save('views.gif')
self.views_recon()
def take_screen(self):
self.driver.save_screenshot('dzen_pars.png')
def navigate(self):
self.driver.get('https://zen.yandex.ru/media/id/5a9d345c1aa80c262cd25c42/3-ujasnye-oshibki-v-otjimaniiah-meshaiuscie-rostu-grudi-5aa7c0739b403cd7a6cc68f4')
views = self.driver.find_element_by_xpath('/html/body/article/div/div[2]/div')
sleep(3)
self.take_screen()
location = views.location
size = views.size
self.crop(location, size)
def main():
b = Bot_dzen()
if __name__ == '__main__':
main()
image.crop((x + <ширина иконки глаз>, y, x + width - <ширина иконки глаз>, y + height)).save('views.gif')