I
I
Ilya Vegner2018-03-17 21:02:02
Python
Ilya Vegner, 2018-03-17 21:02:02

Pytesseract does not correctly take values ​​from the image, what is the reason for this?

I've been struggling with a problem for a whole day.
When trying to take the given one using image_to_string, it does not take them correctly

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')
    print(image_to_string(image))

  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/artishok-prirodnyi-celitel-dlia-pecheni-top-poleznyh-svoistv-i-kak-ego-prinimat-5aa8ba4f9b403c50c355e94c')
    views = self.driver.find_element_by_xpath('/html/body/article/div/div[2]')

    sleep(3)

    self.take_screen()

    location = views.location
    size = views.size

    self.crop(location, size)

def main():
  b = Bot_dzen()

if __name__ == '__main__':
  main()

I need to take the entire div with the article-stat class and take the data from there

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question