@dark_spectator

В чем ошибка? Pytesseract?

проблема при переводе картинки в текст. Использую модуль pytesseract.
Файл tel.gif создаётся и там только номер телефона.

Вот код:
import requests
from selenium import webdriver
from time import sleep
from bs4 import BeautifulSoup
from PIL import Image
from pytesseract import image_to_string
class Bot:
	def __init__(self, url):
		self.name = self.get_seller_name(url)
		print(self.name)
		self.driver = webdriver.Firefox()
		self.navigate(url)

	def get_seller_name(self, url):
		r = requests.get(url)
		html = r.text
		soup = BeautifulSoup(html, 'lxml')
		seller_name = soup.find('div', class_='seller-info-name').text.strip()
		return seller_name

	def take_screenshot(self):
		self.driver.save_screenshot('avito_screenshot.png')

	def tel_recon(self):
		image = Image.open('tel.gif')
		s = image_to_string(image)
		print(s)

	def crop(self, location, size):
		image = Image.open('avito_screenshot.png')
		x = location['x']
		y = location['y']
		image.crop( (222, 90, x + 317, y - 25 ) ).save('tel.gif')
		self.tel_recon()

	def navigate(self, url):

		self.driver.get(url)
		button = self.driver.find_element_by_xpath('//button[@class="button item-phone-button js-item-phone-button button-origin button-origin-blue button-origin_full-width button-origin_large-extra item-phone-button_hide-phone item-phone-button_card js-item-phone-button_card"]')
		button.click()
		sleep(3)
		self.take_screenshot()
		image = self.driver.find_element_by_xpath('//div[@class="item-popup-content js-item-phone-popup-content"]')
		location = image.location # dictionary {'x': 243, 'y': 234}
		print(size)
		print(location)		  # dictionary {'width': 234, 'height': 234}
		self.crop(location, size)


def main():
	url = 'https://www.avito.ru/samara/odezhda_obuv_aksessuary/zimnyaya_kurtka_novaya_1118930094'
	res = Bot(url)


if __name__ == '__main__':
	main()


Вот ошибка:
Traceback (most recent call last):
  File "avitoGetTell.py", line 58, in <module>
    main()
  File "avitoGetTell.py", line 54, in main
    res = Bot(url)
  File "avitoGetTell.py", line 12, in __init__
    self.navigate(url)
  File "avitoGetTell.py", line 49, in navigate
    self.crop(location, size)
  File "avitoGetTell.py", line 34, in crop
    self.tel_recon()
  File "avitoGetTell.py", line 26, in tel_recon
    s = image_to_string(image)
  File "C:\Users\Dark\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pytesseract\pytesseract.py", line 122, in image_to_string
    config=config)
  File "C:\Users\Dark\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pytesseract\pytesseract.py", line 46, in run_tesseract
    proc = subprocess.Popen(command, stderr=subprocess.PIPE)
  File "C:\Users\Dark\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "C:\Users\Dark\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 997, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] Не удается найти указанный файл

В чем проблема?
Сразу скажу что не очень хорошо знаю python.
  • Вопрос задан
  • 509 просмотров
Пригласить эксперта
Ответы на вопрос 1
dimonchik2013
@dimonchik2013
non progredi est regredi
полный путь к файлу укажи
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы