2018-1-10 Program For Million Heroes
2018-01-10 09:12
225 查看
##Version 1.1.1 ##Time:2018-1-10 ##Author:十三月 import subprocess from PIL import Image import pytesseract import requests from bs4 import BeautifulSoup import time ###得到屏幕截图 def pull_screenshot(): process = subprocess.Popen('adb shell screencap -p', shell=True, stdout=subprocess.PIPE) screenshot = process.stdout.read() binary_screenshot = screenshot.replace(b'\r\n', b'\n') f = open('screenpic.png', 'wb') f.write(binary_screenshot) f.close() ###识别图中文字 def getImagecode(): image = Image.open('screenpic.png') box = (50, 300, 1000, 600) cutimage = image.crop(box) box2 = (50, 620, 1000, 1220) cutimage2 = image.crop(box2) code = pytesseract.image_to_string(cutimage, lang='chi_sim').strip() code2 = pytesseract.image_to_string(cutimage2, lang='chi_sim').strip() codelist = [code, code2] print(code) print(code2) return codelist ###解析百度页面 def getpageindex(keyword): params = { "Cookie": "",##此处填入浏览器中的cookie "Host": "www.baidu.com", "Upgrade-Insecure-Requests": '1', "User-Agent": "",##此处填入浏览器中的User-Agent } url = "https://www.baidu.com/s?cl=3&wd={}".format(keyword) res = requests.get(url, headers=params) soup = BeautifulSoup(res.text, 'lxml') answers = soup.select('.c-abstract') return answers ###红色显示答案文字 def distinguish(str1, str2): for x1 in str1: if x1 in str2: print("\033[0;31m%s\033[0m" % x1, end='') else: print(x1, end='') def main(): inputstate = input('Run program input [0]:') start = time.clock() if inputstate == '0': pull_screenshot() [keyword, answord] = getImagecode() answers = getpageindex(keyword) print('--' * 10) for i in range(len(answers)): try: answer = answers[i].text.strip() print('[%d]' % i, end='') distinguish(answer, answord) print('\n') except: pass else: pass end = time.clock() print('Running time: %s Seconds' % (end-start)) if __name__ == '__main__': main()
相关文章推荐
- Create a shortcut for a program at user Desktop
- GREE Announces $10 Million Investment Fund for Mobile Games Developers
- C program for quick sort
- VS 安装助手,弹出“The security key for this program currently stored on your system does not appear to be ”
- Program for Fibonacci numbers
- CareerCup Program an iterator for a Linked List which may include nodes which are nested within othe
- Error launching remote program: failed to get the task for process
- C program for 折半查找
- Data Structure Array: Program for array rotation
- [Amazon] Program for Fibonacci numbers 斐波那契数列
- How to estimate the time required for a program.
- 微软MSIT部门招Program Manager for FSS team
- Record for Individual Project ( Word frequency program )
- Java Program for Establishing a Server Connection
- Archive for required library:E:program Files/apache-maven-3.1.0/repository/org/springframework/sprin
- Program for Android in C/C++ with the Native Development Kit (if you dare)
- Modify the average program to promote for intergers repeatedly.stop when a nagetive number is entere
- Iphone真机调试出错:launching remote program: failed to get the task for process XXX
- Program serial number for xmc4300 by J-Link + J-Flash
- build program for hpc 2.02