Millions of hero type answer game programmer open way
How do Programmers Play Summit? Greatly inspired, just a few days ago to study the assistance of wechat jump jump, just can be used.
The idea is very clear, pull the screenshot of the answer, identify it into text through OCR and then put it into Baidu search. After a few attempts, some easily searchable questions are still searchable.
Currently it is manual, meaning that each time an answer appears, the script is manually executed to return the answer. Also due to individual topic reasons (such as the number of strokes of a word), can not be searched every time. This is a test of your hand speed and luck.
To implement the language Python, use the following class library:
- PIL
- Pytesseract (Image Recognition Library)
- BeautifulSoup (Page parsing)
The character recognition engine needs to be installed separately. See blog.csdn.net/qiushi_1990… And tesserACt-OCR for MAC
The theme code is as follows:
import os from PIL import Image import pytesseract from urllib.request import urlopen import urllib.request from bs4 import BeautifulSoup DEFAULT_WIDTH = 720 DEFAULT_HEIGHT = 1280 def main(): Left_top_x = 30 left_top_y = 200 right_bottom_x = 680 right_bottom_y = 380 # 1 # os.system('adb pull /sdcard/answer.png') # os.system('adb pull /sdcard/answer.png') # 2. Image = image.open ('answer.png') crop_img = image.crop((left_top_x, left_top_y, right_bottom_x, right_bottom_y)) crop_img.save('crop.png') text = pytesseract.image_to_string(crop_img, lang='chi_sim') print(text) # 3. Wd = urllib.request.quote(text) url = urllib.request.quote(text) url = urllib.request.quote(text) url = urllib.request.quote(text) url = urllib.request.quote(text 'https://zhidao.baidu.com/search?ct=17&pn=0&tn=ikaslist&rn=10&fr=wwwt&word={}'.format( wd) print(url) result = urlopen(url) body = BeautifulSoup(result.read(), 'html5lib') good_result_div = body.find(class_='list-header').find('dd') second_result_div = body.find(class_='list-inner').find(class_='list') if good_result_div is not None: good_result = good_result_div.get_text() print(good_result.strip()) if second_result_div is not None: second_result = second_result_div.find('dl').find('dd').get_text() print(second_result.strip()) if __name__ == '__main__': main()Copy the code
I posted the code on Github for hQ-answer-Assist
To achieve more intelligent, there is a train of thought is screenshot once (1 second), once cut to answer the questions on page (can be done with the answer page color difference), make baidu, character recognition of baidu after result with options, which appear most times which is the best answer, here you can add a judgment, if special determine directly simulate click events to choose the answer, When in doubt, do it.
Some students mentioned analyzing the request, which is also an idea that can be studied later.
Welcome to explore other, better ways to do this.