Use Python to quickly search for question-answering apps

Source: Internet
Author: User
Tags tesseract ocr

1. Preface

Recent answer class app is relatively hot, because the topic is wide and short time, their typing search is not likely, so want to do an automatic search of the Python script

The Python script is the principle of using the ADB tool to upload a mobile phone to the computer for word recognition, and then Baidu search for the problem, open the browser time or relatively slow

2. Text Recognition Library pytesseract2.1 installation of Pytesseract Library

The installation of this library is particularly easy, and on the command line enter

pip install pytesseract

Can be installed

2.2 Tesseract OCR engine

The Tesseract OCR engine is an open source, powerful engine that installs windows and then uses the relevant variable settings to

2.3 image_to_string function

This function is a method of Pytesseract library, converting picture text to text

fromimport Imageimport= pytesseract.image_to_string(question_img, lang='chi_sim').replace(' ','')

The above is the base usage, and the space is replaced

3.ADB Tools 3.1 Introduction

ADB full name Android Debug Bridge, through which you can interact with the installation phone on the command line on the computer side, provided the phone turns on USB debugging

The ADB has a number of features that simulate a screen strike, and the first hot hop-and-hop assist is done using this principle

Use ADB in 3.2python code

Using the ADB shell in Python code is simple

import osdef pull_screenshot():    os.system('adb shell screencap -p /sdcard/screenshot.png')    os.system('adb pull /sdcard/screenshot.png')

This allows you to impersonate the command-line input to send the phone to the script directory

4. Complete code
 fromPILImportImageImportPytesseractImportTimeImportOsImportWebBrowserdefPull_screenshot (): Os.system (' adb shell screencap-p/sdcard/screenshot.png ') Os.system (' adb pull/sdcard/screenshot.png ')defMain (): Pull_screenshot () img=Image.Open("./screenshot.png") question_img=Img.crop (( $, -,1019,621)) Question_text=Pytesseract.image_to_string (question_img, Lang=' Chi_sim '). Replace (' ','') WebBrowser.Open("https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&rsv_idx=2&tn=baiduhome_pg&wd="+Question_text)if __name__ == ' __main__ ': Main ()

After the use of the discovery time-consuming or relatively long, after the identification of 1-2s to open the browser to search, and then we find the answer, it may be time to

So the improvement can use crawlers, selected search results related pages to search keywords, search for answers to troubleshoot

Use Python to quickly search for question-answering apps

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.